# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
20980 | 2017-03-26T06:39:13 Z | ainta | Ili (COI17_ili) | C++14 | 2996 ms | 2680 KB |
#include<cstdio> #include<algorithm> #include<vector> using namespace std; int n, m, E[20100][2]; char p[10100]; vector<int> G[20100]; int Get(char *a){ int i, s = 0; for(i=1;a[i];i++)s=s*10+a[i]-'0'; if(a[0]=='x')return s; return s+n; } int v[20100]; struct point{ int a, b, c; }w[20100]; void DFS(int a){ v[a]=1; if(a<=n)return; int i; for(i=0;i<2;i++){ if(!v[E[a][i]])DFS(E[a][i]); } } int Q[20100], head, tail; int vv[20100]; bool Pos(int a, int b){ int i; if(!a){ for(i=1;i<=n+m;i++)v[i]=0; for(i=1;i<=m;i++){ if(p[i]=='1' && !v[n+i]) v[n+i] = 2; } for(i=1;i<=m;i++){ if(p[i]=='0' && !v[n+i])DFS(n+i); } } else{ for(i=1;i<=n+m;i++)v[i]=vv[i]; if(b==1) DFS(a); else v[a] = b; } for(i=1;i<=m;i++){ if(!v[w[i].c]){ if(v[w[i].a] == 1 && v[w[i].b] == 1) v[w[i].c] = 1; } } head = tail = 0; for(i=1;i<=n+m;i++){ if(v[i]==2)Q[++tail] = i; } while(head < tail){ int x = Q[++head]; if(x > n){ if(v[E[x][0]] == 1 && v[E[x][1]] == 0){ v[E[x][1]] = 2; Q[++tail] = E[x][1]; } if(v[E[x][1]] == 1 && v[E[x][0]] == 0){ v[E[x][0]] = 2; Q[++tail] = E[x][0]; } } for(i=0;i<G[x].size();i++){ if(!v[G[x][i]]){ v[G[x][i]] = 2; Q[++tail] = G[x][i]; } } } for(i=1;i<=m;i++){ if(v[w[i].a]==1 && v[w[i].b]==1 && v[w[i].c] == 2)return false; if((v[w[i].a]==2 || v[w[i].b]==2) && v[w[i].c] == 1)return false; } return true; } int main(){ int i; scanf("%d%d",&n,&m); scanf("%s",p+1); char p1[20], p2[20]; for(i=1;i<=m;i++){ scanf("%s%s",p1,p2); int t1 = Get(p1), t2 = Get(p2); E[n+i][0] = t1; E[n+i][1] = t2; G[t1].push_back(n+i); G[t2].push_back(n+i); w[i].a = t1, w[i].b = t2, w[i].c = n+i; } DFS(0); Pos(0,0); for(i=1;i<=n+m;i++)vv[i] = v[i]; for(i=1;i<=m;i++){ if(vv[n+i]){ printf("%d",vv[n+i]-1); continue; } if(!Pos(n+i, 1)){ printf("1"); } else if(!Pos(n+i, 2)){ printf("0"); } else printf("?"); } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2284 KB | Output is correct |
2 | Correct | 0 ms | 2284 KB | Output is correct |
3 | Correct | 0 ms | 2284 KB | Output is correct |
4 | Correct | 0 ms | 2284 KB | Output is correct |
5 | Correct | 0 ms | 2284 KB | Output is correct |
6 | Correct | 0 ms | 2284 KB | Output is correct |
7 | Correct | 0 ms | 2284 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2284 KB | Output is correct |
2 | Correct | 0 ms | 2284 KB | Output is correct |
3 | Correct | 0 ms | 2284 KB | Output is correct |
4 | Correct | 0 ms | 2284 KB | Output is correct |
5 | Correct | 0 ms | 2284 KB | Output is correct |
6 | Correct | 0 ms | 2284 KB | Output is correct |
7 | Correct | 0 ms | 2284 KB | Output is correct |
8 | Correct | 0 ms | 2284 KB | Output is correct |
9 | Correct | 0 ms | 2284 KB | Output is correct |
10 | Correct | 0 ms | 2284 KB | Output is correct |
11 | Correct | 0 ms | 2284 KB | Output is correct |
12 | Correct | 0 ms | 2284 KB | Output is correct |
13 | Correct | 0 ms | 2284 KB | Output is correct |
14 | Correct | 0 ms | 2284 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2284 KB | Output is correct |
2 | Correct | 0 ms | 2284 KB | Output is correct |
3 | Correct | 0 ms | 2284 KB | Output is correct |
4 | Correct | 0 ms | 2284 KB | Output is correct |
5 | Correct | 0 ms | 2284 KB | Output is correct |
6 | Correct | 0 ms | 2284 KB | Output is correct |
7 | Correct | 0 ms | 2284 KB | Output is correct |
8 | Correct | 0 ms | 2284 KB | Output is correct |
9 | Correct | 0 ms | 2284 KB | Output is correct |
10 | Correct | 0 ms | 2284 KB | Output is correct |
11 | Correct | 0 ms | 2284 KB | Output is correct |
12 | Correct | 0 ms | 2284 KB | Output is correct |
13 | Correct | 0 ms | 2284 KB | Output is correct |
14 | Correct | 0 ms | 2284 KB | Output is correct |
15 | Correct | 59 ms | 2416 KB | Output is correct |
16 | Correct | 1303 ms | 2548 KB | Output is correct |
17 | Correct | 536 ms | 2548 KB | Output is correct |
18 | Correct | 2549 ms | 2548 KB | Output is correct |
19 | Correct | 839 ms | 2548 KB | Output is correct |
20 | Correct | 2673 ms | 2548 KB | Output is correct |
21 | Correct | 2996 ms | 2680 KB | Output is correct |
22 | Correct | 316 ms | 2680 KB | Output is correct |
23 | Correct | 289 ms | 2680 KB | Output is correct |
24 | Correct | 279 ms | 2680 KB | Output is correct |
25 | Correct | 683 ms | 2420 KB | Output is correct |
26 | Correct | 659 ms | 2420 KB | Output is correct |
27 | Correct | 656 ms | 2420 KB | Output is correct |
28 | Correct | 576 ms | 2420 KB | Output is correct |
29 | Correct | 606 ms | 2420 KB | Output is correct |
30 | Correct | 636 ms | 2420 KB | Output is correct |
31 | Correct | 739 ms | 2572 KB | Output is correct |
32 | Correct | 789 ms | 2556 KB | Output is correct |