Submission #546229

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