Submission #343304

#TimeUsernameProblemLanguageResultExecution timeMemory
343304apostoldaniel854Crazy old lady (IZhO13_crazy)C++14
100 / 100
36 ms492 KiB
#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 timeMemoryGrader output
Fetching results...