#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
6 ms |
888 KB |
Output is correct |
9 |
Correct |
4 ms |
888 KB |
Output is correct |
10 |
Correct |
5 ms |
888 KB |
Output is correct |
11 |
Correct |
5 ms |
1016 KB |
Output is correct |
12 |
Correct |
5 ms |
888 KB |
Output is correct |
13 |
Correct |
5 ms |
1020 KB |
Output is correct |
14 |
Correct |
5 ms |
1016 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
6 ms |
888 KB |
Output is correct |
9 |
Correct |
4 ms |
888 KB |
Output is correct |
10 |
Correct |
5 ms |
888 KB |
Output is correct |
11 |
Correct |
5 ms |
1016 KB |
Output is correct |
12 |
Correct |
5 ms |
888 KB |
Output is correct |
13 |
Correct |
5 ms |
1020 KB |
Output is correct |
14 |
Correct |
5 ms |
1016 KB |
Output is correct |
15 |
Correct |
80 ms |
8028 KB |
Output is correct |
16 |
Correct |
319 ms |
9192 KB |
Output is correct |
17 |
Correct |
247 ms |
11000 KB |
Output is correct |
18 |
Correct |
1067 ms |
12780 KB |
Output is correct |
19 |
Correct |
461 ms |
9272 KB |
Output is correct |
20 |
Correct |
1331 ms |
12764 KB |
Output is correct |
21 |
Correct |
2681 ms |
12936 KB |
Output is correct |
22 |
Correct |
2047 ms |
12372 KB |
Output is correct |
23 |
Correct |
2271 ms |
12860 KB |
Output is correct |
24 |
Correct |
2117 ms |
12920 KB |
Output is correct |
25 |
Execution timed out |
4025 ms |
12792 KB |
Time limit exceeded |
26 |
Halted |
0 ms |
0 KB |
- |