This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("no-stack-protector")
#define F first
#define S second
#define sz(x) int(x.size())
#define pb push_back
#define pf push_front
#define N 100010
#define M ll(1e9 + 7)
#define inf 1e9 + 1e9
using namespace std;
//using namespace __gnu_pbds;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef short int si;
typedef array <ll, 3> a3;
typedef array <int, 4> a4;
typedef pair <int, ll> pt;
//typedef tree <int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
int n, m;
string s, t;
pair <int, int> from[N];
void go_bad(int v, bool f)
{
if (f) s[v] = '0'; else t[v] = '0';
if (v < m) {go_bad(from[v].F, f); go_bad(from[v].S, f);}
}
bool fnd(int v)
{
if (v >= m) return (s[v] == '1');
return fnd(from[v].F) | fnd(from[v].S);
}
int main()
{
//freopen("mining.in", "r", stdin); freopen("mining.out", "w", stdout);
ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m;
cin >> s;
for (int i = 0; i < n; i++) s += '1';
for (int i = 0; i < m; i++)
{
char c1, c2;
int x1, x2;
cin >> c1 >> x1 >> c2 >> x2;
x1--; x2--;
if (c1 == 'x') x1 += m;
if (c2 == 'x') x2 += m;
from[i] = {x1, x2};
}
for (int i = 0; i < m; i++)
if (s[i] == '0') go_bad(i, 1);
for (int i = 0; i < m; i++)
if (s[i] == '?')
{
if (!fnd(i)) {s[i] = '0'; continue;}
t = s;
go_bad(i, 0);
for (int j = 0; j < m; j++)
if (t[from[j].F] == '1' || t[from[j].S] == '1') t[j] = '1'; else t[j] = '0';
bool bad = 0;
for (int j = 0; j < m; j++)
if (s[j] == '1' && t[j] == '0') {bad = 1; break;}
if (bad) s[i] = '1';
}
for (int i = 0; i < m; i++) cout << s[i];
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |