Submission #466120

#TimeUsernameProblemLanguageResultExecution timeMemory
466120SirCovidThe19thIli (COI17_ili)C++17
100 / 100
616 ms1352 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 = stoi(a.substr(1)) + (a[0] == 'c' ? n : 0); v = stoi(b.substr(1)) + (b[0] == 'c' ? n : 0); in[i].push_back(u - 1); in[i].push_back(v - 1); } 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[in[i][0]] == '0' and A[in[i][1]] == '0') A[i] = '0'; for (int i = n; i < n + m; i++){ if (A[i] == '?'){ bool ok0 = 1; vector<char> tmp = A; set0(tmp, i); for (int j = n; j < n + m and ok0; j++){ char &in1 = tmp[in[j][0]], &in2 = tmp[in[j][1]], &cur = tmp[j]; if (in1 == '0' and in2 == '0') cur = '0'; else if (in1 == '1' or in2 == '1') cur = '1'; if (j == i and cur == '1') ok0 = 0; if (A[j] != '?' and cur != A[j]) ok0 = 0; } cout<<(ok0 ? "?" : "1"); } else cout<<A[i]; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...