Submission #316601

#TimeUsernameProblemLanguageResultExecution timeMemory
316601thecodingwizardWalk (POI13_spa)C++11
12 / 100
5108 ms206520 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; int n, k; set<ll> dead; ll read() { ll num = 0; for (int i = n-1; i >= 0; i--) { char c; cin >> c; if (c == '1') { num |= (1 << i); } } return num; } // return true if a can reach b or if a can reach at least ct nodes bool solve(ll a, ll b, int ct) { set<ll> vis; queue<ll> q; q.push(a); vis.insert(a); while (!q.empty()) { ll u = q.front(); q.pop(); for (int i = 0; i < n; i++) { ll v = u ^ (1LL << i); if (vis.count(v) || dead.count(v)) continue; vis.insert(v); if ((int)vis.size() == ct || v == b) return true; q.push(v); } } return false; } int main() { cin.tie(0)->sync_with_stdio(0); cin >> n >> k; ll a, b; a = read(), b = read(); for (int i = 0; i < k; i++) { ll x = read(); dead.insert(x); } cout << (solve(a, b, n*k+1) && solve(b, a, n*k+1) ? "TAK" : "NIE") << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...