# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
744449 | rainboy | Crazy old lady (IZhO13_crazy) | C11 | 11 ms | 300 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 <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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |