이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <stdio.h>
#define N 3000000
int main() {
int t;
scanf("%d", &t);
while (t--) {
static int aa[N], uu[N * 2], vv[N * 2];
static char flipped[N];
int n, cnt, h, i, j, p, good, tmp;
scanf("%d", &n), n /= 2;
for (i = 0; i < n * 2; i++)
scanf("%d", &aa[i]), aa[i]--;
good = 1;
for (i = 0; i < n; i++)
if (aa[i] + aa[n * 2 - 1 - i] != n * 2 - 1) {
good = 0;
break;
}
if (!good) {
printf("-1\n");
continue;
}
good = 1;
for (i = 0; i < n; i++)
if ((flipped[i] = aa[i] > aa[n * 2 - 1 - i])) {
good ^= 1;
aa[i] = aa[n * 2 - 1 - i];
}
if (!good) {
printf("-1\n");
continue;
}
cnt = 0;
for (i = 0, p = -1; i < n; i++) {
while ((j = aa[i]) != i) {
tmp = aa[i], aa[i] = aa[j], aa[j] = tmp;
if (!flipped[i])
uu[cnt] = i, vv[cnt] = j, cnt++;
else
uu[cnt] = i, vv[cnt] = n * 2 - 1 - j, cnt++;
flipped[i] ^= flipped[j], flipped[j] = 0;
}
if (flipped[i]) {
if (p == -1)
p = i;
else {
uu[cnt] = i, vv[cnt] = p, cnt++;
uu[cnt] = n * 2 - 1 - i, vv[cnt] = n * 2 - 1 - p, cnt++;
p = -1;
}
}
}
printf("%d %d\n", cnt, cnt);
for (h = 0; h < cnt; h++)
printf("%d %d\n", uu[h] + 1, vv[h] + 1);
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
cat.c: In function 'main':
cat.c:8:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
8 | scanf("%d", &t);
| ^~~~~~~~~~~~~~~
cat.c:14:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | scanf("%d", &n), n /= 2;
| ^~~~~~~~~~~~~~~
cat.c:16:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
16 | scanf("%d", &aa[i]), aa[i]--;
| ^~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |