# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
26360 | tlwpdus | Ili (COI17_ili) | C++98 | 416 ms | 2136 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |