#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef complex<long double> point;
const int maxn = 2e4 + 10;
int n, m;
int a[maxn], b[maxn];
int x[maxn], y[maxn];
int get(string s){
int sz = s.size();
int ret = 0;
if (s[0] == 'c')
ret += n;
return ret + stoi(s.substr(1, sz-1));
}
int main(){
ios_base::sync_with_stdio(false);
cin >> n >> m;
string s;
cin >> s;
memset(a, -1, sizeof a);
for (int i = 1; i <= m; i++){
if (s[i-1] == '1')
a[i+n] = 1;
if (s[i-1] == '0')
a[i+n] = 0;
}
for (int i = n+1; i <= n+m; i++){
string f, s;
cin >> f >> s;
x[i] = get(f), y[i] = get(s);
}
for (int i = n+m; i >= n+1; i--)
if (a[i] == 0)
a[x[i]] = a[y[i]] = 0;
for (int i = n+1; i <= n+m; i++)
if (a[x[i]] == 1 or a[y[i]] == 1)
a[i] = 1;
else if (a[x[i]] == 0 and a[y[i]] == 0)
a[i] = 0;
for (int i = n+1; i <= n+m; i++){
if (a[i] != -1)
continue;
for (int j = 1; j <= n; j++){
if (a[j] == -1)
b[j] = 1;
else
b[j] = a[j];
}
for (int j = n+1; j <= n+m; j++)
b[j] = a[j];
bool found = 0;
b[i] = 0;
for (int j = i; j >= n+1; j--)
if (b[j] == 0)
b[x[j]] = b[y[j]] = 0;
for (int j = n+1; j <= n+m; j++){
b[j] = (b[x[j]] | b[y[j]]);
if (a[j] == 1 and b[j] == 0){
found = 1;
break;
}
}
if (found){
a[i] = 1;
for (int j = i; j <= n+m; j++)
if (a[x[j]] == 1 or a[y[j]] == 1)
a[j] = 1;
}
}
for (int i = n+1; i <= n+m; i++)
if (a[i] == -1)
cout << '?';
else
cout << a[i];
cout << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
512 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
512 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
512 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
512 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
512 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
512 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
512 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
13 ms |
640 KB |
Output is correct |
16 |
Correct |
85 ms |
656 KB |
Output is correct |
17 |
Correct |
53 ms |
640 KB |
Output is correct |
18 |
Correct |
151 ms |
748 KB |
Output is correct |
19 |
Correct |
65 ms |
760 KB |
Output is correct |
20 |
Correct |
204 ms |
760 KB |
Output is correct |
21 |
Correct |
197 ms |
768 KB |
Output is correct |
22 |
Correct |
45 ms |
760 KB |
Output is correct |
23 |
Correct |
53 ms |
760 KB |
Output is correct |
24 |
Correct |
53 ms |
768 KB |
Output is correct |
25 |
Correct |
140 ms |
760 KB |
Output is correct |
26 |
Correct |
138 ms |
760 KB |
Output is correct |
27 |
Correct |
141 ms |
760 KB |
Output is correct |
28 |
Correct |
128 ms |
760 KB |
Output is correct |
29 |
Correct |
140 ms |
760 KB |
Output is correct |
30 |
Correct |
136 ms |
760 KB |
Output is correct |
31 |
Correct |
172 ms |
760 KB |
Output is correct |
32 |
Correct |
205 ms |
780 KB |
Output is correct |