#include <bits/stdc++.h>
#define task "I"
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define Rep(i, r, l) for (int i = (r); i >= (l); --i)
#define DB(X) { cerr << #X << " = " << (X) << '\n'; }
#define DB1(A, _) { cerr << #A << "[" << _ << "] = " << (A[_]) << '\n'; }
#define DB2(A, _, __) { cerr << #A << "[" << _ << "][" << __ << "] = " << (A[_][__]) << '\n'; }
#define DB3(A, _, __, ___) { cerr << #A << "[" << _ << "][" << __ << "][" << ___ << "] = " << (A[_][__][___]) << '\n'; }
#define PR(A, l, r) { cerr << '\n'; rep(_, l, r) DB1(A, _); cerr << '\n';}
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
#define pf push_front
#define F first
#define S second
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } // sort(arr, arr + N, by(a));
#define next ___next
#define prev ___prev
#define y1 ___y1
#define left ___left
#define right ___right
#define y0 ___y0
#define div ___div
#define j0 ___j0
#define jn ___jn
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using namespace std;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vl;
const int N = 1e4 + 2;
int n, m, type[N << 1];
bool in[N << 1];
vi g[N], gr[N << 1];
void fill0(int u)
{
type[u] = 0;
if (u < m) for (int v : g[u]) fill0(v);
}
vi allx1;
void canReach1(int u)
{
if (u >= m)
{
if (type[u] == 1) allx1.eb(u);
return;
}
for (int v : g[u]) canReach1(v);
}
int main()
{
#ifdef HynDuf
freopen(task".in", "r", stdin);
//freopen(task".out", "w", stdout);
#else
ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif
cin >> n >> m;
rep(i, 0, n + m) type[i] = -1;
string s;
cin >> s;
rep(i, 0, m - 1) if (s[i] != '?') type[i] = s[i] - '0';
rep(i, 0, m - 1)
{
string s1, s2;
cin >> s1 >> s2;
if (s1[0] == 'x') g[i].eb(m + (s1[1] - '1')), gr[m + (s1[1] - '1')].eb(i);
else g[i].eb(s1[1] - '1'), gr[s1[1] - '1'].eb(i);
if (s2[0] == 'x') g[i].eb(m + (s2[1] - '1')), gr[m + (s2[1] - '1')].eb(i);
else g[i].eb(s2[1] - '1'), gr[s2[1] - '1'].eb(i);
}
rep(i, 0, m - 1) if (type[i] == 0) fill0(i);
rep(i, m, n + m - 1) if (type[i] == -1) type[i] = 1;
rep(i, 0, m - 1) if (type[i] == -1)
{
allx1.clear();
canReach1(i);
bool can1 = !allx1.empty(), can0 = 1;
//PR(allx1, 0, SZ(allx1) - 1);
fill(in, in + n + m, 0);
for (int v : allx1) in[v] = 1;
queue<int> q;
rep(j, m, n + m - 1) if (!in[j] && type[j] == 1) q.push(j);
while (!q.empty())
{
int u = q.front();
q.pop();
for (int v : gr[u]) if (!in[v]) q.push(v), in[v] = 1;
}
rep(j, 0, m - 1) if (type[j] == 1 && !in[j]) can0 = 0;
if (can0 ^ can1) type[i] = (can0 ? 0 : 1);
}
rep(i, 0, m - 1) if (type[i] == -1) cout << '?';
else cout << type[i];
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1024 KB |
Output is correct |
2 |
Correct |
1 ms |
1024 KB |
Output is correct |
3 |
Incorrect |
1 ms |
1024 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1024 KB |
Output is correct |
2 |
Correct |
1 ms |
1024 KB |
Output is correct |
3 |
Incorrect |
1 ms |
1024 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1024 KB |
Output is correct |
2 |
Correct |
1 ms |
1024 KB |
Output is correct |
3 |
Incorrect |
1 ms |
1024 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |