# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
917336 | rainboy | 줄서기 (KOI17_line) | C++98 | 154 ms | 21836 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 <stdlib.h>
#define N 100000
int *ei[N], eo[N];
void append(int j, int i) {
int o = eo[j]++;
if (o >= 2 && (o & o - 1) == 0)
ei[j] = (int *) realloc(ei[j], o * 2 * sizeof *ei[j]);
ei[j][o] = i;
}
int main() {
static int aa[N];
int n, m, h, i, j, o;
scanf("%d%d", &n, &m);
for (j = 0; j < n; j++)
ei[j] = (int *) malloc(2 * sizeof *ei[j]);
for (h = 0; h < m; h++) {
scanf("%d%d", &i, &j), i--, j--;
append(j, i);
}
for (j = 0; j < n; j++) {
for (o = eo[j]; o--; ) {
i = ei[j][o];
if (aa[i]++ < j - eo[j]) {
printf("-1\n");
return 0;
}
}
aa[j] = j - eo[j];
}
for (i = 0; i < n; i++)
printf("%d ", aa[i] + 1);
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... |