# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
26297 | 2017-06-29T05:57:31 Z | 김동현(#1101) | Ili (COI17_ili) | C++14 | 3919 ms | 3848 KB |
#include <bits/stdc++.h> using namespace std; int n, m, dp[20010]; char str[10010], ans[10010]; vector<int> e[20010], re[20010]; int can(){ fill(dp + 1, dp + n + m + 1, 0); for(int i = n + m; i >= 1; i--){ if(i > n){ if(str[i - n] == '0') dp[i] = -1; else if(str[i - n] == '1'){ for(auto &j : re[i]) if(dp[j] == -1) return 0; dp[i] = 1; } else{ for(auto &j : re[i]) if(dp[j] == -1){ dp[i] = -1; break; } } } else{ for(auto &j : re[i]) if(dp[j] == -1){ dp[i] = -1; break; } } } for(int i = n + 1; i <= n + m; i++){ if(dp[i] == 1){ if(dp[e[i][0]] == -1){ if(dp[e[i][1]] == -1) return 0; dp[e[i][1]] = 1; } else if(dp[e[i][1]] == -1) dp[e[i][0]] = 1; } else if(!dp[i]){ if(dp[e[i][0]] == 1 || dp[e[i][1]] == 1) dp[i] = 1; else if(dp[e[i][0]] == -1 && dp[e[i][1]] == -1) dp[i] = -1; } else{ if(dp[e[i][0]] == 1 || dp[e[i][1]] == 1) return 0; } } return 1; } int main(){ scanf("%d%d%s", &n, &m, str + 1); for(int i = 1, x, y; i <= m; i++){ char a[10], b[10]; scanf("%s%s", &a, &b); sscanf(a + 1, "%d", &x); sscanf(b + 1, "%d", &y); if(a[0] == 'c') x += n; if(b[0] == 'c') y += n; e[n + i].push_back(x); e[n + i].push_back(y); re[x].push_back(n + i); re[y].push_back(n + i); } for(int i = 1; i <= m; i++){ if(str[i] != '?'){ ans[i] = str[i]; continue; } str[i] = '0'; if(!can()){ str[i] = '?'; ans[i] = '1'; continue; } str[i] = '1'; if(can()) ans[i] = '?'; else ans[i] = '0'; str[i] = '?'; } puts(ans + 1); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 3056 KB | Output is correct |
2 | Correct | 0 ms | 3056 KB | Output is correct |
3 | Correct | 0 ms | 3056 KB | Output is correct |
4 | Correct | 0 ms | 3056 KB | Output is correct |
5 | Correct | 0 ms | 3056 KB | Output is correct |
6 | Correct | 0 ms | 3056 KB | Output is correct |
7 | Correct | 0 ms | 3056 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 3056 KB | Output is correct |
2 | Correct | 0 ms | 3056 KB | Output is correct |
3 | Correct | 0 ms | 3056 KB | Output is correct |
4 | Correct | 0 ms | 3056 KB | Output is correct |
5 | Correct | 0 ms | 3056 KB | Output is correct |
6 | Correct | 0 ms | 3056 KB | Output is correct |
7 | Correct | 0 ms | 3056 KB | Output is correct |
8 | Correct | 0 ms | 3056 KB | Output is correct |
9 | Correct | 3 ms | 3056 KB | Output is correct |
10 | Correct | 0 ms | 3056 KB | Output is correct |
11 | Correct | 3 ms | 3056 KB | Output is correct |
12 | Correct | 0 ms | 3056 KB | Output is correct |
13 | Correct | 0 ms | 3056 KB | Output is correct |
14 | Correct | 0 ms | 3056 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 3056 KB | Output is correct |
2 | Correct | 0 ms | 3056 KB | Output is correct |
3 | Correct | 0 ms | 3056 KB | Output is correct |
4 | Correct | 0 ms | 3056 KB | Output is correct |
5 | Correct | 0 ms | 3056 KB | Output is correct |
6 | Correct | 0 ms | 3056 KB | Output is correct |
7 | Correct | 0 ms | 3056 KB | Output is correct |
8 | Correct | 0 ms | 3056 KB | Output is correct |
9 | Correct | 3 ms | 3056 KB | Output is correct |
10 | Correct | 0 ms | 3056 KB | Output is correct |
11 | Correct | 3 ms | 3056 KB | Output is correct |
12 | Correct | 0 ms | 3056 KB | Output is correct |
13 | Correct | 0 ms | 3056 KB | Output is correct |
14 | Correct | 0 ms | 3056 KB | Output is correct |
15 | Correct | 476 ms | 3452 KB | Output is correct |
16 | Correct | 1633 ms | 3452 KB | Output is correct |
17 | Correct | 1179 ms | 3584 KB | Output is correct |
18 | Correct | 2666 ms | 3584 KB | Output is correct |
19 | Correct | 1606 ms | 3452 KB | Output is correct |
20 | Correct | 3313 ms | 3716 KB | Output is correct |
21 | Correct | 3919 ms | 3716 KB | Output is correct |
22 | Correct | 363 ms | 3848 KB | Output is correct |
23 | Correct | 403 ms | 3848 KB | Output is correct |
24 | Correct | 379 ms | 3848 KB | Output is correct |
25 | Correct | 773 ms | 3484 KB | Output is correct |
26 | Correct | 769 ms | 3484 KB | Output is correct |
27 | Correct | 813 ms | 3484 KB | Output is correct |
28 | Correct | 719 ms | 3484 KB | Output is correct |
29 | Correct | 726 ms | 3484 KB | Output is correct |
30 | Correct | 753 ms | 3484 KB | Output is correct |
31 | Correct | 789 ms | 3608 KB | Output is correct |
32 | Correct | 929 ms | 3584 KB | Output is correct |