Submission #7285781


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;

template <class T>
inline bool read(T &ret)
{
    char c;
    int sgn;
    if (c = getchar(), c == EOF)
    {
        return 0;
    }
    while (c != '-' && (c < '0' || c > '9'))
    {
        c = getchar();
    }
    sgn = (c == '-') ? -1 : 1;
    ret = (c == '-') ? 0 : (c - '0');
    while (c = getchar(), c >= '0' && c <= '9')
    {
        ret = ret * 10 + (c - '0');
    }
    ret *= sgn;
    return 1;
}

template <class T>
inline void write(T x)
{
    if (x > 9)
    {
        write(x / 10);
    }
    putchar(x % 10 + '0');
}

const int MAXN=1010;
int n,ans;
bool vised[MAXN];
queue<int> que[MAXN];

int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<n;j++)
        {
            int sr;
            cin>>sr;
            que[i].push(sr);
        }
    }
    ans=0;
    while(true)
    {
        for(int i=1;i<=n;i++)
            vised[i]=false;
        bool pd=false;
        for(int i=1;i<=n;i++)
        {
            if(!que[i].empty()&&!vised[i])
            {
                int cc=que[i].front();
                if(!vised[i]&&i==que[cc].front())
                {
                    que[i].pop();
                    que[cc].pop();
                    vised[i]=true;
                    vised[cc]=true;
                    pd=true;
                    cout<<i<<" "<<cc<<" "<<ans<<endl;
                }
            }
        }
        if(!pd)
            break;
        ans++;
    }
    for(int i=1;i<=n;i++)
        if(!que[i].empty())
        {
            cout<<"-1"<<endl;
            return 0;
        }
    cout<<ans+1<<endl;
}

Submission Info

Submission Time
Task E - League
User Setsuge
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1713 Byte
Status WA
Exec Time 2103 ms
Memory 10368 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 500
Status
AC × 1
WA × 2
AC × 3
WA × 19
TLE × 1
Set Name Test Cases
Sample a01, a02, a03
All a01, a02, a03, b04, b05, b06, b07, b08, b09, b10, b11, b12, b13, b14, b15, b16, b17, b18, b19, b20, b21, b22, b23
Case Name Status Exec Time Memory
a01 WA 2 ms 896 KB
a02 WA 2 ms 896 KB
a03 AC 2 ms 896 KB
b04 WA 2 ms 896 KB
b05 WA 2 ms 896 KB
b06 WA 2 ms 896 KB
b07 AC 2 ms 896 KB
b08 TLE 2103 ms 9856 KB
b09 AC 212 ms 4736 KB
b10 WA 1097 ms 10368 KB
b11 WA 1111 ms 10368 KB
b12 WA 314 ms 3584 KB
b13 WA 265 ms 2944 KB
b14 WA 102 ms 1664 KB
b15 WA 96 ms 1664 KB
b16 WA 19 ms 1024 KB
b17 WA 35 ms 1152 KB
b18 WA 211 ms 2688 KB
b19 WA 171 ms 2304 KB
b20 WA 20 ms 1024 KB
b21 WA 42 ms 1152 KB
b22 WA 6 ms 1024 KB
b23 WA 7 ms 896 KB