제출 #307454

#제출 시각아이디문제언어결과실행 시간메모리
307454HynDufIli (COI17_ili)C++11
0 / 100
1 ms1024 KiB
#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, 1); for (int v : allx1) in[v] = 0; rep(j, 0, n + m - 1) if (type[j] == 0) in[j] = 0; rep(j, 0, m - 1) { if (in[g[j][0]] || in[g[j][1]]) in[j] = 1; else if (type[j] == 1) { type[i] = 1; break; } } } rep(i, 0, m - 1) if (type[i] == -1) cout << '?'; else cout << type[i]; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...