Submission #227701

#TimeUsernameProblemLanguageResultExecution timeMemory
227701emil_physmathCrazy old lady (IZhO13_crazy)C++17
100 / 100
66 ms640 KiB
#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 timeMemoryGrader output
Fetching results...