This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxn = 1e4 + 10;
#define pb push_back
#define migmig ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ms(x , y) memset(x , y , sizeof x)
#define dokme(x) cout << x, exit(0);
int n , m;
string s;
char c[maxn][2];
int a[maxn][2];
vector < int > ans[2];
bitset < maxn > x[maxn] , zero;
bool chk(int pos){
if(x[pos].count() > 5000){
x[pos].flip();
for(int i : ans[1]){
bool ok = 0;
for(int j = x[pos]._Find_first() ; j < maxn ; j = x[pos]._Find_next(j))
if(x[i][j]){
ok = 1;
break;
}
if(!ok)return(0);
}
}
else{
for(int i : ans[1]){
bool ok = 0;
for(int j = x[i]._Find_first() ; j < maxn ; j = x[i]._Find_next(j))
if(x[pos][j] == 0){
ok = 1;
break;
}
if(!ok)return(0);
}
}
return(1);
}
int32_t main(){
migmig;
cin >> n >> m >> s;
s = "6" + s;
for(int i = 1 ; i <= m ; i ++){
for(int j = 0 ; j < 2 ; j ++){
cin >> c[i][j] >> a[i][j] , a[i][j] += ((c[i][j] == 'c') ? n : 0);
if(a[i][j] <= n)x[i][a[i][j]] = 1;
else
for(int v = x[a[i][j] - n]._Find_first() ; v < maxn ; v = x[a[i][j] - n]._Find_next(v))
x[i][v] = 1;
}
if(s[i] == '0')ans[0].pb(i);
if(s[i] == '1')ans[1].pb(i);
}
for(int i : ans[0])
zero |= x[i];
for(int i = 1 ; i <= m ; i ++){
x[i] ^= (zero & x[i]);
if(x[i].count() == 0 and s[i] == '?')
s[i] = '0';
}
for(int i = 1 ; i <= m ; i ++)if(s[i] == '?'){
if(!chk(i))
s[i] = '1';
}
for(int i = 1 ; i <= m ; i ++)
cout << s[i];
return(0);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |