Submission #26360

#TimeUsernameProblemLanguageResultExecution timeMemory
26360tlwpdusIli (COI17_ili)C++98
49 / 100
416 ms2136 KiB
#include <bits/stdc++.h> using namespace std; int n, m; char str[20100]; char ttr[20100]; int son[10100][2]; int getn(char str[]) { int i, x = 0; for (i=0;str[i]>='0'&&str[i]<='9';i++) { x *=10; x+=str[i]-'0'; } return x; } bool can0(int idx) { int i; for (i=0;i<n+m;i++) ttr[i] = str[i]; ttr[idx] = '0'; for (i=n+m;i>=n;i--) { if (ttr[i]=='0') { if (ttr[son[i][0]]=='1'||ttr[son[i][1]]=='1') return false; ttr[son[i][1]]=ttr[son[i][0]]='0'; } } for (i=n;i<n+m;i++) { if (ttr[son[i][0]]=='0'&&ttr[son[i][1]]=='0') { if (ttr[i]=='1') return false; ttr[i]='0'; } } for (i=n;i<n+m;i++) { if (ttr[i]=='?') { if (ttr[son[i][0]]=='0'&&ttr[son[i][1]]=='0') ttr[i]='0'; else ttr[i]='1'; } if (ttr[i]=='1'&&ttr[son[i][0]]=='0'&&ttr[son[i][1]]=='0') return false; if (ttr[i]=='0'&&(ttr[son[i][0]]=='1'||ttr[son[i][1]]=='1')) return false; } return true; } int main() { int i, j; //freopen("input","r",stdin); scanf("%d%d",&n,&m); scanf("%s",str+n); fill(str,str+n,'?'); for (i=0;i<m;i++) { char buf[10]; for (j=0;j<2;j++) { int x = 0; scanf("%s",buf); if (buf[0]=='c') x+= n; x+=getn(buf+1)-1; son[i+n][j] = x; } } for (i=n+m-1;i>=n;i--) { if (str[i]=='0') { str[son[i][1]]=str[son[i][0]]='0'; } } for (i=n;i<n+m;i++) { if (str[son[i][0]]=='0'&&str[son[i][1]]=='0') str[i]='0'; } for (i=n;i<n+m;i++) { if (str[i]=='?') { if (!can0(i)) str[i] = '1'; } } printf("%s\n",str+n); return 0; }

Compilation message (stderr)

ili.cpp: In function 'int main()':
ili.cpp:51:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&m);
                        ^
ili.cpp:52:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%s",str+n);
                      ^
ili.cpp:58:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%s",buf);
                            ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...