이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/* In the name of Allah */
#include<bits/stdc++.h>
using namespace std;
const int N = 1e4 + 5;
vector<int> adj[N][2];
bitset<N> B[N], Z;
bool mark[N];
int n, m;
string c;
int read() {
string s;
cin >> s;
int u = stoi(s.substr(1));
if (s[0] ^ 'x')
u += n;
return --u;
}
void read_input() {
cin >> n >> m >> c;
for (int i = 0; i < m; i++)
for (auto u: {read(), read()})
if (u < n) {
B[i].set(u);
adj[i][0].push_back(u);
}
else {
B[i] |= B[u -= n];
adj[i][1].push_back(u);
}
}
void solve() {
for (int u = 0; u < m; u++)
if (c[u] == '0')
Z |= B[u];
for (int u = 0; u < m; u++) {
B[u] ^= Z & B[u];
if (!B[u].count())
c[u] = '0';
}
for (int u = 0; u < m; u++)
if (c[u] == '?') {
bool flag = true;
bitset<N> W = Z | B[u];
for (int v = 0; v < m; v++) {
mark[v] = false;
for (auto x: adj[v][1])
mark[v] |= mark[x];
for (auto x: adj[v][0])
mark[v] |= !W[x];
flag &= mark[v] || c[v] != '1';
}
if (!flag)
c[u] = '1';
}
cout << c;
}
int main() {
ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
read_input(), solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |