Submission #343304

# Submission time Handle Problem Language Result Execution time Memory
343304 2021-01-03T16:02:29 Z apostoldaniel854 Crazy old lady (IZhO13_crazy) C++14
100 / 100
36 ms 492 KB
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define dbg(x) cerr << #x << " " << x << "\n"
using ll = long long;
const int MAX_N = 1000;
int p[1 + MAX_N];
bool used[1 + MAX_N];

void solveTest () {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> p[i];
    vector <int> crazy_old_lady_seat;
    for (int pos = 1; pos <= n; pos++) {
        for (int i = 1; i <= n; i++)
            used[i] = false;
        used[p[1]] = true;
        bool ok = true;
        for (int i = 2; i <= n; i++) {
            int to_take = i;
            if (to_take <= pos)
                to_take--;
            if (p[i] != to_take && not used[to_take])
                ok = false;
            used[p[i]] = true;
        }
        if (ok)
            crazy_old_lady_seat.pb (pos);
    }
    if (crazy_old_lady_seat.size () != 1)
        cout << 0 << "\n";
    else
        cout << crazy_old_lady_seat.back () << "\n";
}

int main () {
    ios::sync_with_stdio (false);
    cin.tie (0); cout.tie (0);
    int t;
    cin >> t;
    while (t--)
        solveTest ();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 3 ms 364 KB Output is correct
9 Correct 4 ms 364 KB Output is correct
10 Correct 6 ms 364 KB Output is correct
11 Correct 7 ms 364 KB Output is correct
12 Correct 9 ms 364 KB Output is correct
13 Correct 10 ms 364 KB Output is correct
14 Correct 13 ms 364 KB Output is correct
15 Correct 15 ms 364 KB Output is correct
16 Correct 20 ms 364 KB Output is correct
17 Correct 20 ms 364 KB Output is correct
18 Correct 30 ms 364 KB Output is correct
19 Correct 30 ms 492 KB Output is correct
20 Correct 36 ms 364 KB Output is correct