# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
97448 | 2019-02-16T08:42:12 Z | Kastanda | Crazy old lady (IZhO13_crazy) | C++11 | 10 ms | 512 KB |
// I do it for the glory #include<bits/stdc++.h> using namespace std; const int N = 1003; int n, q, P[N], M[N]; inline bool Check(int id) { memset(M, 0, sizeof(M)); M[P[1]] = 1; for (int i = 1; i <= n; i++) if (i != id) { int j = i + (i < id); if (M[P[j]]) return 0; if (P[j] != i && !M[i]) return 0; M[P[j]] = 1; } return 1; } int main() { scanf("%d", &q); for (; q; q --) { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &P[i]); int cz = -1; for (int i = 1; i <= n; i++) if (Check(i)) { if (cz != -1) {cz = -2; break;} else cz = i; } if (cz == -2) printf("0\n"); else printf("%d\n", cz); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 512 KB | Output is correct |
2 | Correct | 3 ms | 384 KB | Output is correct |
3 | Correct | 4 ms | 384 KB | Output is correct |
4 | Correct | 2 ms | 384 KB | Output is correct |
5 | Correct | 2 ms | 256 KB | Output is correct |
6 | Correct | 2 ms | 384 KB | Output is correct |
7 | Correct | 3 ms | 384 KB | Output is correct |
8 | Correct | 4 ms | 384 KB | Output is correct |
9 | Correct | 4 ms | 384 KB | Output is correct |
10 | Correct | 5 ms | 384 KB | Output is correct |
11 | Correct | 4 ms | 384 KB | Output is correct |
12 | Correct | 4 ms | 384 KB | Output is correct |
13 | Correct | 5 ms | 384 KB | Output is correct |
14 | Correct | 6 ms | 384 KB | Output is correct |
15 | Correct | 7 ms | 384 KB | Output is correct |
16 | Correct | 7 ms | 384 KB | Output is correct |
17 | Correct | 8 ms | 384 KB | Output is correct |
18 | Correct | 9 ms | 384 KB | Output is correct |
19 | Correct | 9 ms | 384 KB | Output is correct |
20 | Correct | 10 ms | 384 KB | Output is correct |