Submission #316612

#TimeUsernameProblemLanguageResultExecution timeMemory
316612thecodingwizardWalk (POI13_spa)C++11
12 / 100
5084 ms152184 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; int n, k; gp_hash_table<ll, null_type> dead({},{},{},{},{1<<20}); ll read() { string s; cin >> s; ll num = 0; for (int i = n-1; i >= 0; i--) { if (s[n-1-i] == '1') { num |= (1LL << 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) { gp_hash_table<ll, null_type> vis({},{},{},{},{1<<23}); queue<ll> q; q.push(a); vis.insert(a); --ct; while (!q.empty()) { ll u = q.front(); q.pop(); for (int i = 0; i < n; i++) { ll v = u ^ (1LL << i); if (vis.find(v) != vis.end() || dead.find(v) != dead.end()) continue; --ct; if (ct == 0 || v == b) return true; vis.insert(v); q.push(v); } } return false; } int main() { cin.tie(0)->sync_with_stdio(0); cin >> n >> k; ll a, b; a = read(), b = read(); if (a == b) { cout << "TAK\n"; return 0; } for (int i = 0; i < k; i++) { ll x = read(); dead.insert(x); } cout << (solve(a, b, 1000000) && solve(b, a, 1000000) ? "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...