# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
944503 | rainboy | 입력숫자 (KOI13_mystery) | C11 | 1 ms | 748 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 30
int n;
int ds[N], rr[N]; char marked[N];
int find(int i) {
return ds[i] < 0 ? i : (ds[i] = find(ds[i]));
}
void join(int i, int j) {
i = find(i);
j = find(j);
if (i == j)
return;
if (ds[i] > ds[j])
ds[i] = j;
else {
if (ds[i] == ds[j])
ds[i]--;
ds[j] = i, rr[i] = rr[j];
}
}
int next(int i) {
return !marked[i] ? i : (rr[find(i)] + 1) % n;
}
void mark(int i) {
marked[i] = 1;
if (marked[(i - 1 + n) % n])
join((i - 1 + n) % n, i);
if (marked[(i + 1) % n])
join(i, (i + 1) % n);
}
int main() {
static int aa[N];
int h, i;
scanf("%d", &n);
memset(ds, -1, n * sizeof *ds);
for (i = 0; i < n; i++)
rr[i] = i;
i = 0;
for (h = 0; h < n; h++) {
i = next(i);
scanf("%d", &aa[i]);
mark(i);
i = (i + aa[i]) % n;
}
printf("%d\n", n);
for (i = 0; i < n; i++)
printf("%d ", aa[i]);
printf("\n");
return 0;
}
Compilation message (stderr)
# | 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... |