Submission #546230

#TimeUsernameProblemLanguageResultExecution timeMemory
546230sidonCrazy old lady (IZhO13_crazy)C++17
100 / 100
29 ms212 KiB
#include <bits/stdc++.h> using namespace std; int main() { int T; cin >> T; while(T--) { int N; cin >> N; int p[N], ans = N; for(int &i : p) cin >> i, --i; for(int i = N; i--; ) { bool vis[N] {}, ok = 1; vis[*p] = 1; for(int j = 1; j < N; vis[p[j++]] = 1) if(!vis[j - (j <= i)] && p[j] != j - (j <= i)) ok = 0; if(ok && ans >= 0) ans = ans == N ? i : -1; } cout << (ans % N) + 1 << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...