# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
249008 | 2020-07-14T03:35:59 Z | luciocf | Ili (COI17_ili) | C++14 | 352 ms | 1656 KB |
#include <bits/stdc++.h> using namespace std; const int maxn = 2e4+10; int n, m; int a[maxn], b[maxn]; int l[maxn], r[maxn]; bool mark[maxn]; vector<int> grafo[maxn]; void dfs(int u) { mark[u] = 1; a[u] = 0; if (!mark[l[u]]) dfs(l[u]); if (!mark[r[u]]) dfs(r[u]); } void do_1(void) { while (true) { for (int i = n+1; i <= n+m; i++) if (a[i] == 0 && !mark[i]) dfs(i); bool novo = 0; for (int i = n+1; i <= n+m; i++) { if (a[i] == -1 && a[l[i]] == 0 && a[r[i]] == 0) a[i] = 0; if (a[i] == 0 && !mark[i]) { novo = 1; break; } } if (!novo) break; } } bool dfs2(int u) { if (b[u] == 1) return false; mark[u] = 1, b[u] = 0; if (!mark[l[u]] && !dfs2(l[u])) return false; if (!mark[r[u]] && !dfs2(r[u])) return false; for (auto v: grafo[u]) { if (b[v] == 1) { if (l[v] == u && b[r[v]] == 0) return false; else if (r[v] == u && b[l[v]] == 0) return false; } else if (b[v] == -1) { if ((l[v] == u && b[r[v]] == 0) || (r[v] == u && b[l[v]] == 0)) { b[v] = 0; if (!mark[v] && !dfs2(v)) return false; } } } return true; } bool can(int u) { memset(mark, 0, sizeof mark); for (int i = 1; i <= n+m; i++) b[i] = a[i]; b[u] = 0; return dfs2(u); } int main(void) { scanf("%d %d", &n, &m); memset(a, -1, sizeof a); for (int i = 1; i <= m; i++) { char c; scanf(" %c", &c); if (c == '1') a[n+i] = 1; else if (c == '0') a[n+i] = 0; } for (int i = 1; i <= m; i++) { char c1; int c2; scanf(" %c %d", &c1, &c2); if (c1 == 'x') { l[n+i] = c2; grafo[c2].push_back(n+i); } else { l[n+i] = n+c2; grafo[n+c2].push_back(n+i); } scanf(" %c %d", &c1, &c2); if (c1 == 'x') { r[n+i] = c2; grafo[c2].push_back(n+i); } else { r[n+i] = n+c2; grafo[n+c2].push_back(n+i); } } do_1(); for (int i = 1; i <= n+m; i++) { if (a[i] != -1) continue; if (!can(i)) a[i] = 1; } for (int i = n+1; i <= n+m; i++) { if (a[i] == -1) printf("?"); else if (a[i] == 0) printf("0"); else printf("1"); } printf("\n"); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 896 KB | Output is correct |
2 | Correct | 0 ms | 896 KB | Output is correct |
3 | Correct | 1 ms | 896 KB | Output is correct |
4 | Correct | 1 ms | 768 KB | Output is correct |
5 | Correct | 1 ms | 896 KB | Output is correct |
6 | Correct | 1 ms | 896 KB | Output is correct |
7 | Correct | 1 ms | 896 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 896 KB | Output is correct |
2 | Correct | 0 ms | 896 KB | Output is correct |
3 | Correct | 1 ms | 896 KB | Output is correct |
4 | Correct | 1 ms | 768 KB | Output is correct |
5 | Correct | 1 ms | 896 KB | Output is correct |
6 | Correct | 1 ms | 896 KB | Output is correct |
7 | Correct | 1 ms | 896 KB | Output is correct |
8 | Correct | 1 ms | 768 KB | Output is correct |
9 | Correct | 1 ms | 896 KB | Output is correct |
10 | Correct | 1 ms | 896 KB | Output is correct |
11 | Correct | 2 ms | 896 KB | Output is correct |
12 | Correct | 2 ms | 896 KB | Output is correct |
13 | Correct | 1 ms | 896 KB | Output is correct |
14 | Correct | 2 ms | 896 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 896 KB | Output is correct |
2 | Correct | 0 ms | 896 KB | Output is correct |
3 | Correct | 1 ms | 896 KB | Output is correct |
4 | Correct | 1 ms | 768 KB | Output is correct |
5 | Correct | 1 ms | 896 KB | Output is correct |
6 | Correct | 1 ms | 896 KB | Output is correct |
7 | Correct | 1 ms | 896 KB | Output is correct |
8 | Correct | 1 ms | 768 KB | Output is correct |
9 | Correct | 1 ms | 896 KB | Output is correct |
10 | Correct | 1 ms | 896 KB | Output is correct |
11 | Correct | 2 ms | 896 KB | Output is correct |
12 | Correct | 2 ms | 896 KB | Output is correct |
13 | Correct | 1 ms | 896 KB | Output is correct |
14 | Correct | 2 ms | 896 KB | Output is correct |
15 | Correct | 26 ms | 1152 KB | Output is correct |
16 | Correct | 53 ms | 1280 KB | Output is correct |
17 | Correct | 55 ms | 1280 KB | Output is correct |
18 | Correct | 80 ms | 1408 KB | Output is correct |
19 | Correct | 58 ms | 1280 KB | Output is correct |
20 | Correct | 97 ms | 1528 KB | Output is correct |
21 | Correct | 120 ms | 1536 KB | Output is correct |
22 | Correct | 94 ms | 1656 KB | Output is correct |
23 | Correct | 93 ms | 1656 KB | Output is correct |
24 | Correct | 92 ms | 1656 KB | Output is correct |
25 | Correct | 284 ms | 1372 KB | Output is correct |
26 | Correct | 289 ms | 1368 KB | Output is correct |
27 | Correct | 289 ms | 1280 KB | Output is correct |
28 | Correct | 273 ms | 1360 KB | Output is correct |
29 | Correct | 282 ms | 1280 KB | Output is correct |
30 | Correct | 294 ms | 1280 KB | Output is correct |
31 | Correct | 350 ms | 1400 KB | Output is correct |
32 | Correct | 352 ms | 1408 KB | Output is correct |