# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
546229 | sidon | Crazy old lady (IZhO13_crazy) | C++17 | 31 ms | 352 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |