# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
26324 | 2017-06-29T08:12:45 Z | 서규호(#1103) | Ili (COI17_ili) | C++14 | 2859 ms | 2224 KB |
#include <bits/stdc++.h> #define lld long long #define pp pair<int,int> #define pb push_back #define MOD 1000000007 #define left lleft #define right rright #define Inf 2000000000 #define Linf 1000000000000000000LL #define next nnext #define minus mminus using namespace std; int N,M; int a[10002],num1[10002],num2[10002]; int tmp[20002]; char s[10010]; bool calc(int x,int y){ for(int i=1; i<=M; i++) tmp[N+i] = a[i]; for(int i=1; i<=N; i++) tmp[i] = 2; tmp[x+N] = y; for(int i=M+N; i>N; i--){ if(tmp[i] != 0) continue; if(tmp[num1[i-N]] == 1 || tmp[num2[i-N]] == 1) return false; tmp[num1[i-N]] = tmp[num2[i-N]] = 0; } for(int i=1; i<=N; i++){ if(tmp[i] != 0) tmp[i] = 1; } for(int i=N+1; i<=N+M; i++){ if(tmp[i] == 1){ if(tmp[num1[i-N]] == 0 && tmp[num2[i-N]] == 0) return false; }else if(tmp[i] == 2){ if(tmp[num1[i-N]]+tmp[num2[i-N]] > 0) tmp[i] = 1; else tmp[i] = 0; } } return true; } int main(){ scanf("%d %d",&N,&M); scanf("%s",s); for(int i=1; i<=M; i++){ if(s[i-1] == '?') a[i] = 2; else a[i] = s[i-1]-'0'; } for(int i=1; i<=M; i++){ int ten; char s1[10],s2[10]; scanf("%s %s",s1,s2); ten = 1; for(int j=strlen(s1)-1; j>=1; j--){ num1[i] += ten*(s1[j]-'0'); ten *= 10; } ten = 1; for(int j=strlen(s2)-1; j>=1; j--){ num2[i] += ten*(s2[j]-'0'); ten *= 10; } if(s1[0] == 'c') num1[i] += N; if(s2[0] == 'c') num2[i] += N; } bool update; while(1){ update = false; for(int i=M; i>=1; i--){ if(a[i] != 2) continue; bool flag1,flag2; flag1 = calc(i,0); flag2 = calc(i,1); if(!flag2){ a[i] = 0; update = true; }else if(!flag1){ a[i] = 1; update = true; } } if(!update) break; } for(int i=1; i<=M; i++){ if(a[i] == 2) printf("?"); else printf("%c",'0'+a[i]); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2224 KB | Output is correct |
2 | Correct | 0 ms | 2224 KB | Output is correct |
3 | Correct | 0 ms | 2224 KB | Output is correct |
4 | Correct | 0 ms | 2224 KB | Output is correct |
5 | Correct | 0 ms | 2224 KB | Output is correct |
6 | Correct | 0 ms | 2224 KB | Output is correct |
7 | Correct | 0 ms | 2224 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2224 KB | Output is correct |
2 | Correct | 0 ms | 2224 KB | Output is correct |
3 | Correct | 0 ms | 2224 KB | Output is correct |
4 | Correct | 0 ms | 2224 KB | Output is correct |
5 | Correct | 0 ms | 2224 KB | Output is correct |
6 | Correct | 0 ms | 2224 KB | Output is correct |
7 | Correct | 0 ms | 2224 KB | Output is correct |
8 | Correct | 0 ms | 2224 KB | Output is correct |
9 | Correct | 0 ms | 2224 KB | Output is correct |
10 | Correct | 0 ms | 2224 KB | Output is correct |
11 | Correct | 3 ms | 2224 KB | Output is correct |
12 | Correct | 0 ms | 2224 KB | Output is correct |
13 | Correct | 0 ms | 2224 KB | Output is correct |
14 | Correct | 3 ms | 2224 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2224 KB | Output is correct |
2 | Correct | 0 ms | 2224 KB | Output is correct |
3 | Correct | 0 ms | 2224 KB | Output is correct |
4 | Correct | 0 ms | 2224 KB | Output is correct |
5 | Correct | 0 ms | 2224 KB | Output is correct |
6 | Correct | 0 ms | 2224 KB | Output is correct |
7 | Correct | 0 ms | 2224 KB | Output is correct |
8 | Correct | 0 ms | 2224 KB | Output is correct |
9 | Correct | 0 ms | 2224 KB | Output is correct |
10 | Correct | 0 ms | 2224 KB | Output is correct |
11 | Correct | 3 ms | 2224 KB | Output is correct |
12 | Correct | 0 ms | 2224 KB | Output is correct |
13 | Correct | 0 ms | 2224 KB | Output is correct |
14 | Correct | 3 ms | 2224 KB | Output is correct |
15 | Correct | 269 ms | 2224 KB | Output is correct |
16 | Correct | 1186 ms | 2224 KB | Output is correct |
17 | Correct | 1139 ms | 2224 KB | Output is correct |
18 | Correct | 1953 ms | 2224 KB | Output is correct |
19 | Correct | 1106 ms | 2224 KB | Output is correct |
20 | Correct | 2859 ms | 2224 KB | Output is correct |
21 | Correct | 2649 ms | 2224 KB | Output is correct |
22 | Correct | 406 ms | 2224 KB | Output is correct |
23 | Correct | 466 ms | 2224 KB | Output is correct |
24 | Correct | 423 ms | 2224 KB | Output is correct |
25 | Correct | 889 ms | 2224 KB | Output is correct |
26 | Correct | 779 ms | 2224 KB | Output is correct |
27 | Correct | 779 ms | 2224 KB | Output is correct |
28 | Correct | 753 ms | 2224 KB | Output is correct |
29 | Correct | 753 ms | 2224 KB | Output is correct |
30 | Correct | 759 ms | 2224 KB | Output is correct |
31 | Correct | 436 ms | 2224 KB | Output is correct |
32 | Correct | 469 ms | 2224 KB | Output is correct |