# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
101050 | choikiwon | Crazy old lady (IZhO13_crazy) | C++17 | 18 ms | 512 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;
const int MN = 1010;
int N;
int P[MN];
void main2() {
scanf("%d", &N);
for(int i = 0; i < N; i++) {
scanf("%d", &P[i]);
P[i]--;
}
int ans = -1;
for(int i = 0; i < N; i++) {
vector<int> chk(N, 0);
chk[ P[0] ] = 1;
int t = i != 0, ok = 1;
for(int j = 1; j < N; j++) {
if(j - t == i) t = 0;
//cout << i << ' ' << j - t << endl;
if(!chk[j - t] && P[j] != j - t) {
ok = 0;
break;
}
chk[ P[j] ] = 1;
}
if(ok) {
if(ans == -1) ans = i;
else {
ans = -1;
break;
}
}
}
if(ans == -1) printf("0\n");
else printf("%d\n", ans + 1);
}
int TC;
int main() {
scanf("%d", &TC);
while(TC--) main2();
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |