# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
66325 | yusufake | Ili (COI17_ili) | C++98 | 3 ms | 376 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;
#define mp make_pair
#define pb push_back
#define st first
#define nd second
typedef long long ll;
typedef pair < int , int > pp;
const int mod = 1e9 + 7;
const int N = 1e3 + 2;
vector < int > V[N];
int H[N],Q[N],T[N],A[N],B[N],n,m,i,j,k;
string a;
char s[N];
int f(string a){
int i, x = 0;
for(i=1; i<a.size(); i++){
x = x*10 + a[i]-'0';
}
if(a[0] == 'x') x += m;
return x;
}
void g(int x){
if(x==0) return;
g(A[x]); g(B[x]);
H[x] = 1;
}
void h(int x){
if(x==0) return;
h(A[x]); h(B[x]);
if(!H[x] && x > m) V[i].pb(x);
}
int main(){
scanf("%d%d %s",&n,&m,s+1);
for(i=1;i<=m;i++){
cin >> a;
A[i] = f(a);
cin >> a;
B[i] = f(a);
// cout << i << " " << A[i] << " " << B[i] << " aa\n";
}
for(i=1;i<=m;i++)
if(s[i] == '0') g(i);
for(i=1;i<=m;i++){
if(s[i] == '0') continue;
if(s[i] == '1'){
h(i);
T[i] = 1;
continue;
}
h(i);
for(auto x : V[i]) Q[x] = 1;
for(j=1;j<i;j++)
if(T[j]){
for(k=0; k<V[j].size(); k++)
if(!Q[ V[j][k] ])
break;
if(k == V[j].size()) { s[i] = '1'; break; }
}
for(auto x : V[i]) Q[x] = 0;
}
printf("%s",s+1);
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... |