Submission #7275317


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define met(s) memset(s,0, sizeof(s))
const int mod=100000007;
const int maxn=1100;
const int inf = 0x3f3f3f3f;
queue<int> q[maxn];
queue<int> a;
queue<int> b;
bool vis[maxn];
int main()
{
    int n;
    memset(vis,false,sizeof(vis));
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<n-1;j++)
        {
            int x;
            scanf("%d",&x);
            q[i].push(x);
        }
    }
    for(int i=1;i<=n;i++)
    {
        if(!vis[i]&&q[q[i].front()].front()==i)
        {
            a.push(i);
            vis[i]=vis[q[i].front()]=true;
        }
    }
    int ans=0;
    while(!a.empty())
    {
        ans++;
        while(!a.empty())
        {
            int now=a.front();a.pop();
            int nn=q[now].front();
            vis[now]=vis[nn]=false;
            q[nn].pop();
            if(!q[nn].empty()&&q[q[nn].front()].front()==nn)
            {
                vis[nn]=vis[q[nn].front()]=true;
                b.push(nn);
            }
            q[now].pop();
            if(!q[now].empty()&&q[q[now].front()].front()==now)
            {
                vis[now]=vis[q[now].front()]=true;
                b.push(now);
            }
        }
        while(!b.empty())
        {
            a.push(b.front());
            b.pop();
        }
    }
    int fo=1;
    for(int i=1;i<=n;i++) if(!q[i].empty())
    {
        fo=0;
        break;
    }
    if(fo) printf("%d\n",ans);
    else printf("-1\n");
    return 0;
}

Submission Info

Submission Time
Task E - League
User WA_King
Language C++14 (GCC 5.4.1)
Score 500
Code Size 1637 Byte
Status AC
Exec Time 113 ms
Memory 4736 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:17:19: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
                   ^
./Main.cpp:23:27: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d",&x);
                           ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 23
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 1024 KB
a02 AC 2 ms 1024 KB
a03 AC 2 ms 1024 KB
b04 AC 2 ms 1024 KB
b05 AC 2 ms 1024 KB
b06 AC 2 ms 1024 KB
b07 AC 2 ms 1024 KB
b08 AC 93 ms 4736 KB
b09 AC 85 ms 4736 KB
b10 AC 113 ms 4736 KB
b11 AC 111 ms 4736 KB
b12 AC 28 ms 2048 KB
b13 AC 24 ms 1792 KB
b14 AC 12 ms 1280 KB
b15 AC 9 ms 1280 KB
b16 AC 6 ms 1152 KB
b17 AC 4 ms 1024 KB
b18 AC 20 ms 1664 KB
b19 AC 17 ms 1536 KB
b20 AC 7 ms 1152 KB
b21 AC 5 ms 1024 KB
b22 AC 3 ms 1024 KB
b23 AC 2 ms 1024 KB