Submission #227701

# Submission time Handle Problem Language Result Execution time Memory
227701 2020-04-28T13:59:41 Z emil_physmath Crazy old lady (IZhO13_crazy) C++17
100 / 100
66 ms 640 KB
#include <algorithm>
#include <iostream>
#include <vector>
#include <set>
using namespace std;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        vector<int> a(n);
        for (int i = 0; i < n; ++i)
        {
            cin >> a[i];
            --a[i];
        }
        set<int> res;
        for (int x = 0; x < n; ++x)
        {
            bool poss = true;
            vector<int> q;
            q.push_back(x);
            for (int i = 0; i < n; ++i)
                if (i != x)
                    q.push_back(i);
            vector<bool> used(n);
            used[a[0]] = true;
            for (int i = 1; i < n; ++i)
            {
                if (!used[q[i]] && a[i] != q[i])
                {
                    poss = false;
                    break;
                }
                used[a[i]] = true;
            }
            if (poss)
                res.insert(x);
        }
        if (res.size() == 1)
            cout << *res.begin() + 1 << '\n';
        else
            cout << 0 << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 7 ms 384 KB Output is correct
8 Correct 10 ms 384 KB Output is correct
9 Correct 12 ms 384 KB Output is correct
10 Correct 15 ms 384 KB Output is correct
11 Correct 18 ms 384 KB Output is correct
12 Correct 20 ms 384 KB Output is correct
13 Correct 22 ms 384 KB Output is correct
14 Correct 28 ms 384 KB Output is correct
15 Correct 32 ms 384 KB Output is correct
16 Correct 41 ms 256 KB Output is correct
17 Correct 42 ms 384 KB Output is correct
18 Correct 60 ms 640 KB Output is correct
19 Correct 54 ms 384 KB Output is correct
20 Correct 66 ms 384 KB Output is correct