이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 convert(const string &s)
{
int res = 0;
rep(i, 1, SZ(s) - 1) res = res * 10 + (s[i] - '0');
return res - 1;
}
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;
int n1 = convert(s1), n2 = convert(s2);
if (s1[0] == 'x') g[i].eb(m + n1), gr[m + n1].eb(i);
else g[i].eb(n1), gr[n1].eb(i);
if (s2[0] == 'x') g[i].eb(m + n2), gr[m + n2].eb(i);
else g[i].eb(n2), gr[n2].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);
if (allx1.empty())
{
type[i] = 0;
continue;
}
//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])
{
type[i] = 1;
break;
}
}
rep(i, 0, m - 1) if (type[i] == -1) cout << '?';
else cout << type[i];
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... |