#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,tune=native")
using namespace std;
typedef int ll;
const ll mod = 1e9 + 7;
const ll MAXN = 100505;
vector<ll>in[MAXN];
vector<ll>out[MAXN];
ll n, m;
ll mp[MAXN];
void push_one(ll x)
{
if(mp[x] == 0 or mp[x] == 1) return;
mp[x] = 1;
for(auto to : out[x])
{
push_one(to);
}
}
void push_zero(ll x)
{
if(mp[x] == 0) return;
mp[x] = 0;
if(x >= n + 1)
{
for(auto to : in[x])
{
push_zero(to);
}
}
}
bool checker(string S)
{
for(ll i = 1; i <= n + m; ++i)
{
mp[i] = -1ll;;
}
ll sum = 0;
for(ll i = 1; i <= m; ++i)
{
if(S[i - 1] == '0')
{
push_zero(i + n);
sum += i + n;
}
}
for(ll i = 1; i <= n; ++i)
{
push_one(i);
}
bool ret = true;
for(ll i = 1; i <= m; ++i)
{
ll v = i + n;
bool valid1 = true;
bool valid2 = true;
if(S[i - 1] == '0' and mp[v] != 0)
{
valid1 = (false);
}
if(S[i - 1] == '1' and mp[v] != 1)
{
valid2 = (false);
}
if(!valid1 or !valid2) ret = false;
}
if(!ret) return false;
else return true;
}
int main()
{
// ifstream cin("mooyomooyo.in");
// ofstream cout("mooyomooyo.out");
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
string s;
cin >> s;
string ans = s;
for(ll i = 1; i <= m; ++i)
{
string s1, s2;
cin >> s1 >> s2;
ll v1 = 0;
ll v2 = 0;
ll base = 1;
for(ll j = s1.size() - 1; j >= 1; --j)
{
v1 += int(s1[j] - '0') * base;
base *= 10;
}
base = 1;
for(ll j = s2.size() - 1; j >= 1; --j)
{
v2 += int(s2[j] - '0') * base;
base *= 10;
}
if(s1[0] == 'c') v1 += n;
if(s2[0] == 'c') v2 += n;
ll V = i + n;
in[V].push_back(v1);
in[V].push_back(v2);
out[v1].push_back(V);
out[v2].push_back(V);
}
string curr = s;
for(ll i = 1; i <= m; ++i)
{
if(s[i - 1] == '?')
{
bool can1 = false;
bool can2 = false;
// case 0
curr[i - 1] = '0';
if(checker(curr) == true) can1 = !(can1);
// case 1
curr[i - 1] = '1';
if(checker(curr) == true) can2 = !(can2);
if(can1 == can2)
{
ans[i - 1] = '?';
}
else if(can1)
{
ans[i - 1] = '0';
}
else if(can2)
{
ans[i - 1] = '1';
}
curr[i - 1] = s[i - 1];
}
}
cout << ans << "\n";
return 0;
}
// //
// //
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
3 ms |
4956 KB |
Output is correct |
4 |
Correct |
2 ms |
4956 KB |
Output is correct |
5 |
Correct |
2 ms |
4952 KB |
Output is correct |
6 |
Correct |
2 ms |
5188 KB |
Output is correct |
7 |
Correct |
2 ms |
4956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
3 ms |
4956 KB |
Output is correct |
4 |
Correct |
2 ms |
4956 KB |
Output is correct |
5 |
Correct |
2 ms |
4952 KB |
Output is correct |
6 |
Correct |
2 ms |
5188 KB |
Output is correct |
7 |
Correct |
2 ms |
4956 KB |
Output is correct |
8 |
Correct |
4 ms |
5212 KB |
Output is correct |
9 |
Correct |
4 ms |
4952 KB |
Output is correct |
10 |
Correct |
4 ms |
5208 KB |
Output is correct |
11 |
Correct |
4 ms |
5212 KB |
Output is correct |
12 |
Correct |
3 ms |
5212 KB |
Output is correct |
13 |
Correct |
4 ms |
5148 KB |
Output is correct |
14 |
Correct |
5 ms |
5212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
3 ms |
4956 KB |
Output is correct |
4 |
Correct |
2 ms |
4956 KB |
Output is correct |
5 |
Correct |
2 ms |
4952 KB |
Output is correct |
6 |
Correct |
2 ms |
5188 KB |
Output is correct |
7 |
Correct |
2 ms |
4956 KB |
Output is correct |
8 |
Correct |
4 ms |
5212 KB |
Output is correct |
9 |
Correct |
4 ms |
4952 KB |
Output is correct |
10 |
Correct |
4 ms |
5208 KB |
Output is correct |
11 |
Correct |
4 ms |
5212 KB |
Output is correct |
12 |
Correct |
3 ms |
5212 KB |
Output is correct |
13 |
Correct |
4 ms |
5148 KB |
Output is correct |
14 |
Correct |
5 ms |
5212 KB |
Output is correct |
15 |
Correct |
498 ms |
5468 KB |
Output is correct |
16 |
Correct |
1020 ms |
5724 KB |
Output is correct |
17 |
Correct |
1018 ms |
5724 KB |
Output is correct |
18 |
Correct |
2539 ms |
5720 KB |
Output is correct |
19 |
Correct |
1032 ms |
5724 KB |
Output is correct |
20 |
Correct |
2679 ms |
5976 KB |
Output is correct |
21 |
Correct |
3863 ms |
6052 KB |
Output is correct |
22 |
Correct |
592 ms |
5976 KB |
Output is correct |
23 |
Correct |
648 ms |
5976 KB |
Output is correct |
24 |
Correct |
644 ms |
6104 KB |
Output is correct |
25 |
Correct |
602 ms |
5724 KB |
Output is correct |
26 |
Correct |
610 ms |
5724 KB |
Output is correct |
27 |
Correct |
605 ms |
5812 KB |
Output is correct |
28 |
Correct |
552 ms |
5804 KB |
Output is correct |
29 |
Correct |
565 ms |
5804 KB |
Output is correct |
30 |
Correct |
578 ms |
5724 KB |
Output is correct |
31 |
Correct |
488 ms |
5856 KB |
Output is correct |
32 |
Correct |
603 ms |
5720 KB |
Output is correct |