Submission #465873

#TimeUsernameProblemLanguageResultExecution timeMemory
465873SirCovidThe19thIli (COI17_ili)C++17
0 / 100
1 ms716 KiB
#include <bits/stdc++.h> using namespace std; int n, m; vector<char> A; vector<int> in[20005]; void set0(vector<char> &X, int i){ X[i] = '0'; for (auto nxt : in[i]) if (X[nxt] != '0') set0(X, nxt); } int main(){ cin >> n >> m; A.resize(n + m); for (int i = 0; i < n + m; i++){ if (i < n) A[i] = '?'; else cin >> A[i]; } for (int i = n, u, v; i < n + m; i++){ string a, b; cin >> a >> b; u = a[1] - '1' + (a[0] == 'c' ? n : 0); v = b[1] - '1' + (b[0] == 'c' ? n : 0); in[i].push_back(u); in[i].push_back(v); } for (int i = n; i < n + m; i++) if (A[i] == '0') set0(A, i); for (int i = n; i < n + m; i++){ if (A[i] == '?'){ bool ok = 1; vector<char> tmp = A; set0(tmp, i); for (int x = n; x < n + m; x++){ char &in1 = tmp[in[x][0]], &in2 = tmp[in[x][1]], &cur = tmp[x]; if (in1 == '0' and in2 == '0') cur = '0'; if (in1 == '1' or in2 == '1') cur = '1'; if (A[x] != '?' and cur != A[x]){ ok = 0; break; } } cout<<(ok ? '?' : '1'); } else cout<<A[i]; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...