Submission #546230

# Submission time Handle Problem Language Result Execution time Memory
546230 2022-04-06T17:27:28 Z sidon Crazy old lady (IZhO13_crazy) C++17
100 / 100
29 ms 212 KB
#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 time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 3 ms 212 KB Output is correct
9 Correct 4 ms 212 KB Output is correct
10 Correct 5 ms 212 KB Output is correct
11 Correct 6 ms 212 KB Output is correct
12 Correct 8 ms 212 KB Output is correct
13 Correct 9 ms 212 KB Output is correct
14 Correct 11 ms 212 KB Output is correct
15 Correct 12 ms 212 KB Output is correct
16 Correct 17 ms 212 KB Output is correct
17 Correct 17 ms 212 KB Output is correct
18 Correct 23 ms 212 KB Output is correct
19 Correct 25 ms 212 KB Output is correct
20 Correct 29 ms 212 KB Output is correct