# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
744449 | 2023-05-18T14:58:01 Z | rainboy | 성질 급한 지학이 (IZhO13_crazy) | C | 11 ms | 300 KB |
#include <stdio.h> #include <string.h> #define N 1000 int main() { int t; scanf("%d", &t); while (t--) { static int pp[N]; static char used[N]; int n, i, i_, j, good, tmp; scanf("%d", &n); for (i = 0; i < n; i++) scanf("%d", &pp[i]), pp[i]--; i_ = -1; for (i = 0; i < n; i++) { memset(used, 0, n * sizeof *used), used[pp[i]] = 1; good = 1; for (j = 0; j < n; j++) { if (j == i) continue; if (!used[j] && pp[j] != j) { good = 0; break; } used[pp[j]] = 1; } if (good) { if (i_ == -1) i_ = i; else { i_ = -1; break; } } if (i + 1 < n) tmp = pp[i], pp[i] = pp[i + 1], pp[i + 1] = tmp; } printf("%d\n", i_ + 1); } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 0 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 | 1 ms | 212 KB | Output is correct |
9 | Correct | 2 ms | 212 KB | Output is correct |
10 | Correct | 2 ms | 296 KB | Output is correct |
11 | Correct | 3 ms | 300 KB | Output is correct |
12 | Correct | 3 ms | 212 KB | Output is correct |
13 | Correct | 2 ms | 212 KB | Output is correct |
14 | Correct | 3 ms | 300 KB | Output is correct |
15 | Correct | 6 ms | 212 KB | Output is correct |
16 | Correct | 6 ms | 300 KB | Output is correct |
17 | Correct | 7 ms | 212 KB | Output is correct |
18 | Correct | 10 ms | 212 KB | Output is correct |
19 | Correct | 8 ms | 212 KB | Output is correct |
20 | Correct | 11 ms | 212 KB | Output is correct |