# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
487026 |
2021-11-13T19:32:07 Z |
rainboy |
Ili (COI17_ili) |
C |
|
2644 ms |
1888 KB |
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 10000
#define M 10000
int *ej[N + M], eo[N + M], *fi[N + M], fo[N + M];
void append(int **ej, int *eo, int i, int j) {
int o = eo[i]++;
if (o >= 2 && (o & o - 1) == 0)
ej[i] = (int *) realloc(ej[i], o * 2 * sizeof *ej[i]);
ej[i][o] = j;
}
char state[N + M]; int n, m;
int check(char *cc) {
int i, j, o;
memset(state, -1, (n + m) * sizeof *state);
for (j = n + m - 1; j >= 0; j--) {
if (j >= n && cc[j - n] == '0')
state[j] = 0;
if (state[j] == 0)
for (o = fo[j]; o--; ) {
i = fi[j][o];
state[i] = 0;
}
}
for (i = 0; i < n + m; i++) {
if (i < n && state[i] == -1)
state[i] = 1;
if (state[i] == 1)
for (o = eo[i]; o--; ) {
j = ej[i][o];
state[j] = 1;
}
}
for (j = 0; j < m; j++)
if (cc[j] == '1' && state[n + j] != 1)
return 0;
return 1;
}
int main() {
static char cc[M + 1];
int i, j;
scanf("%d%d%s", &n, &m, cc);
for (i = 0; i < n + m; i++) {
ej[i] = (int *) malloc(2 * sizeof *ej[i]);
fi[i] = (int *) malloc(2 * sizeof *fi[i]);
}
for (j = 0; j < m; j++) {
static char aa[8], bb[8];
int u, v;
scanf("%s%s", aa, bb);
u = atoi(aa + 1) + (aa[0] == 'x' ? 0 : n) - 1, v = atoi(bb + 1) + (bb[0] == 'x' ? 0 : n) - 1;
append(ej, eo, u, n + j), append(fi, fo, n + j, u);
append(ej, eo, v, n + j), append(fi, fo, n + j, v);
}
for (j = 0; j < m; j++)
if (cc[j] == '?') {
cc[j] = '0';
if (!check(cc))
cc[j] = '1';
else {
cc[j] = '1';
cc[j] = !check(cc) ? '0' : '?';
}
}
printf("%s\n", cc);
return 0;
}
Compilation message
ili.c: In function 'append':
ili.c:13:23: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
13 | if (o >= 2 && (o & o - 1) == 0)
| ~~^~~
ili.c: In function 'main':
ili.c:52:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
52 | scanf("%d%d%s", &n, &m, cc);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
ili.c:61:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
61 | scanf("%s%s", aa, bb);
| ^~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
3 ms |
332 KB |
Output is correct |
9 |
Correct |
2 ms |
332 KB |
Output is correct |
10 |
Correct |
2 ms |
332 KB |
Output is correct |
11 |
Correct |
3 ms |
332 KB |
Output is correct |
12 |
Correct |
2 ms |
332 KB |
Output is correct |
13 |
Correct |
2 ms |
332 KB |
Output is correct |
14 |
Correct |
3 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
3 ms |
332 KB |
Output is correct |
9 |
Correct |
2 ms |
332 KB |
Output is correct |
10 |
Correct |
2 ms |
332 KB |
Output is correct |
11 |
Correct |
3 ms |
332 KB |
Output is correct |
12 |
Correct |
2 ms |
332 KB |
Output is correct |
13 |
Correct |
2 ms |
332 KB |
Output is correct |
14 |
Correct |
3 ms |
332 KB |
Output is correct |
15 |
Correct |
392 ms |
972 KB |
Output is correct |
16 |
Correct |
1086 ms |
1136 KB |
Output is correct |
17 |
Correct |
1036 ms |
1228 KB |
Output is correct |
18 |
Correct |
1975 ms |
1452 KB |
Output is correct |
19 |
Correct |
1083 ms |
1208 KB |
Output is correct |
20 |
Correct |
2359 ms |
1696 KB |
Output is correct |
21 |
Correct |
2644 ms |
1888 KB |
Output is correct |
22 |
Correct |
675 ms |
1792 KB |
Output is correct |
23 |
Correct |
714 ms |
1816 KB |
Output is correct |
24 |
Correct |
680 ms |
1788 KB |
Output is correct |
25 |
Correct |
875 ms |
1828 KB |
Output is correct |
26 |
Correct |
853 ms |
1828 KB |
Output is correct |
27 |
Correct |
902 ms |
1836 KB |
Output is correct |
28 |
Correct |
808 ms |
1768 KB |
Output is correct |
29 |
Correct |
801 ms |
1800 KB |
Output is correct |
30 |
Correct |
864 ms |
1804 KB |
Output is correct |
31 |
Correct |
828 ms |
1440 KB |
Output is correct |
32 |
Correct |
994 ms |
1508 KB |
Output is correct |