#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'
using namespace std;
typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
const ll Mod = 1000000007LL;
const int N = 2e4 + 10;
const ll Inf = 2242545357980376863LL;
const ll Log = 30;
int n, m, mk[N];
vector<int> G[N];
void DFS(int u){
mk[u] = 1;
for(auto adj : G[u]) if(!mk[adj]) DFS(adj);
}
vector<ll> V;
void DFS2(int u){
mk[u] = 1;
V.pb(u);
for(auto adj : G[u]) if(!mk[adj]) DFS2(adj);
}
int val[N];
void Calc(){
for(int i = n + 1; i <= n + m; i++){
val[i] = 0;
for(auto adj : G[i]) val[i] |= val[adj];
}
}
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m;
str s;
cin >> s;
char c;
int id;
for(int i = n + 1; i <= n + m; i ++){
cin >> c >> id;
G[i].pb((c == 'x' ? 0 : n) + id);
cin >> c >> id;
G[i].pb((c == 'x' ? 0 : n) + id);
}
for(int i = 1; i <= m; i++){
if(s[i - 1] == '0' && !mk[n + i]) DFS(n + i);
}
for(int i = 1; i <= n; i++) val[i] = 1 - mk[i];
Calc();
for(int i = 1; i <= m; i++){
if(val[n + i] == 0) s[i - 1] = '0';
}
for(int j = 1; j <= m; j++){
if(s[j - 1] != '?') continue;
V.clear();
DFS2(n + j);
for(int i = 1; i <= n; i++) val[i] = 1 - mk[i];
Calc();
for(int i = 1; i <= m; i++){
if(s[i - 1] == '1' && val[n + i] == 0) s[j - 1] = '1';
}
for(auto &x : V) mk[x] = 0;
}
cout << s << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
768 KB |
Output is correct |
2 |
Correct |
5 ms |
640 KB |
Output is correct |
3 |
Correct |
5 ms |
768 KB |
Output is correct |
4 |
Correct |
5 ms |
896 KB |
Output is correct |
5 |
Correct |
5 ms |
768 KB |
Output is correct |
6 |
Correct |
5 ms |
768 KB |
Output is correct |
7 |
Correct |
5 ms |
768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
768 KB |
Output is correct |
2 |
Correct |
5 ms |
640 KB |
Output is correct |
3 |
Correct |
5 ms |
768 KB |
Output is correct |
4 |
Correct |
5 ms |
896 KB |
Output is correct |
5 |
Correct |
5 ms |
768 KB |
Output is correct |
6 |
Correct |
5 ms |
768 KB |
Output is correct |
7 |
Correct |
5 ms |
768 KB |
Output is correct |
8 |
Correct |
5 ms |
896 KB |
Output is correct |
9 |
Correct |
5 ms |
768 KB |
Output is correct |
10 |
Correct |
5 ms |
820 KB |
Output is correct |
11 |
Correct |
5 ms |
896 KB |
Output is correct |
12 |
Correct |
5 ms |
896 KB |
Output is correct |
13 |
Correct |
5 ms |
896 KB |
Output is correct |
14 |
Correct |
6 ms |
896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
768 KB |
Output is correct |
2 |
Correct |
5 ms |
640 KB |
Output is correct |
3 |
Correct |
5 ms |
768 KB |
Output is correct |
4 |
Correct |
5 ms |
896 KB |
Output is correct |
5 |
Correct |
5 ms |
768 KB |
Output is correct |
6 |
Correct |
5 ms |
768 KB |
Output is correct |
7 |
Correct |
5 ms |
768 KB |
Output is correct |
8 |
Correct |
5 ms |
896 KB |
Output is correct |
9 |
Correct |
5 ms |
768 KB |
Output is correct |
10 |
Correct |
5 ms |
820 KB |
Output is correct |
11 |
Correct |
5 ms |
896 KB |
Output is correct |
12 |
Correct |
5 ms |
896 KB |
Output is correct |
13 |
Correct |
5 ms |
896 KB |
Output is correct |
14 |
Correct |
6 ms |
896 KB |
Output is correct |
15 |
Correct |
106 ms |
1152 KB |
Output is correct |
16 |
Correct |
161 ms |
1280 KB |
Output is correct |
17 |
Correct |
178 ms |
1280 KB |
Output is correct |
18 |
Correct |
363 ms |
1408 KB |
Output is correct |
19 |
Correct |
150 ms |
1280 KB |
Output is correct |
20 |
Correct |
296 ms |
1408 KB |
Output is correct |
21 |
Correct |
394 ms |
1408 KB |
Output is correct |
22 |
Correct |
390 ms |
1780 KB |
Output is correct |
23 |
Correct |
439 ms |
1656 KB |
Output is correct |
24 |
Correct |
432 ms |
1656 KB |
Output is correct |
25 |
Correct |
179 ms |
1400 KB |
Output is correct |
26 |
Correct |
178 ms |
1400 KB |
Output is correct |
27 |
Correct |
184 ms |
1400 KB |
Output is correct |
28 |
Correct |
166 ms |
1400 KB |
Output is correct |
29 |
Correct |
174 ms |
1400 KB |
Output is correct |
30 |
Correct |
173 ms |
1400 KB |
Output is correct |
31 |
Correct |
277 ms |
1528 KB |
Output is correct |
32 |
Correct |
368 ms |
1528 KB |
Output is correct |