Submission #7271330


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 = 1010;
const int inf = 0x3f3f3f3f;
queue<int> q[maxn];
bool vis[maxn];
int main()
{
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j < n; j++)
        {
            int x;
            scanf("%d", &x);
            q[i].emplace(x);
        }
    }
    vector<pair<int, int>> v[2];
    int ans = 0;
    int now = 0;
    int nn = 1;
    for (int i = 1; i <= n; i++)
    {
        int ne = q[i].front();
        if (!vis[ne])
            v[now].emplace_back(i, ne), vis[i] = vis[ne] = true;
    }
    while (true)
    {
        ans++;
        if (v[now].empty())
            break;
        for (auto x : v[now])
            q[x.first].pop(), q[x.second].pop(), vis[x.first] = vis[x.second] = false;
        for (auto x : v[now])
        {
            int ne;
            if (q[x.first].size())
            {
                ne = q[x.first].front();
                if (!vis[x.first] && !vis[ne])
                {
                    if (q[ne].size() && q[ne].front() == x.first)
                        v[nn].emplace_back(x.first, ne), vis[ne] = vis[x.first] = true;
                }
            }
            if (q[x.second].size())
            {
                ne = q[x.second].front();
                if (!vis[x.second] && !vis[ne])
                {
                    if (q[ne].size() && q[ne].front() == x.second)
                        v[nn].emplace_back(x.second, ne), vis[ne] = vis[x.second] = true;
                }
            }
        }
        v[now].clear();
        swap(now, nn);
    }
    for (int i = 1; i <= n; i++)
        if (q[i].size())
            return puts("-1"), 0;
    cout << ans-1;
    return 0;
}

Submission Info

Submission Time
Task E - League
User WA_King
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1931 Byte
Status WA
Exec Time 111 ms
Memory 4736 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:14:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
                    ^
./Main.cpp:20:28: 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 0 / 500
Status
AC × 3
AC × 16
WA × 7
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 WA 2 ms 896 KB
b06 WA 2 ms 896 KB
b07 AC 2 ms 896 KB
b08 WA 86 ms 4736 KB
b09 AC 86 ms 4736 KB
b10 AC 110 ms 4736 KB
b11 AC 111 ms 4736 KB
b12 AC 29 ms 2048 KB
b13 AC 25 ms 1664 KB
b14 AC 12 ms 1280 KB
b15 AC 10 ms 1280 KB
b16 AC 6 ms 1024 KB
b17 AC 5 ms 1024 KB
b18 WA 18 ms 1536 KB
b19 WA 15 ms 1536 KB
b20 AC 7 ms 1024 KB
b21 WA 5 ms 1024 KB
b22 AC 3 ms 1024 KB
b23 WA 2 ms 896 KB