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 MAXN 10004
int main(){
ios::sync_with_stdio(false); cin.tie(0);
int n, m;
cin>>n>>m;
string me; cin>>me;
vector<pair<int, int> > s(m);
for(int i = 0; i < m; i++){
char c1, c2;
int i1, i2;
cin>>c1>>i1>>c2>>i2;
i1--, i2--;
if(c1 == 'x') i1 = i1*-1 - 1;
if(c2 == 'x') i2 = i2*-1 - 1;
s[i] = {i1, i2};
}
vector<bitset<MAXN> > b(m);
for(int i = 0; i < m; i++){
if(s[i].first < 0) b[i].set(s[i].first*-1 - 1);
else b[i] |= b[s[i].first];
if(s[i].second < 0) b[i].set(s[i].second*-1 -1);
else b[i] |= b[s[i].second];
}
bitset<MAXN> zero;
for(int i = 0; i < m; i++){
if(me[i] == '0'){
zero |= b[i];
}
}
zero.flip();
for(int i = 0; i < m; i++){
b[i] &= zero;
}
vector<int> one;
for(int i = 0; i < m; i++){
if(me[i] == '1') one.push_back(i);
}
for(int i = 0; i < m; i++){
if(me[i] != '?') continue;
if(b[i].count() == 0){
me[i] = '0';
continue;
}
for(int j: one){
if((b[i]&b[j]) == b[j]){
me[i] = '1';
break;
}
}
}
cout<<me<<endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |