Submission #7288307


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 1717 Byte
Status WA
Exec Time 1387 ms
Memory 4736 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 500
Status
AC × 3
AC × 12
WA × 11
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 AC 2 ms 896 KB
a02 AC 2 ms 896 KB
a03 AC 2 ms 896 KB
b04 AC 2 ms 896 KB
b05 AC 2 ms 896 KB
b06 WA 2 ms 896 KB
b07 AC 2 ms 896 KB
b08 WA 1387 ms 4736 KB
b09 AC 210 ms 4736 KB
b10 WA 230 ms 4736 KB
b11 AC 229 ms 4736 KB
b12 WA 63 ms 2048 KB
b13 WA 54 ms 1664 KB
b14 AC 27 ms 1280 KB
b15 WA 20 ms 1280 KB
b16 AC 13 ms 1024 KB
b17 WA 8 ms 1024 KB
b18 WA 43 ms 1536 KB
b19 WA 35 ms 1536 KB
b20 AC 13 ms 1024 KB
b21 WA 9 ms 1024 KB
b22 AC 5 ms 1024 KB
b23 WA 3 ms 896 KB