Submission #339554

#TimeUsernameProblemLanguageResultExecution timeMemory
339554Alex_tz307Walk (POI13_spa)C++17
100 / 100
3644 ms54172 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; int N, K; ll x, y; unordered_set<ll> forbidden; bool graphSearch(ll s, ll d, int cnt) { unordered_set<ll> vis; queue<ll> Q; Q.emplace(s); vis.insert(s); --cnt; while(!Q.empty()) { ll v = Q.front(); Q.pop(); for(int i = 0; i < N; ++i) { ll next = v ^ (1LL << i); if(next == d) return true; if(!forbidden.count(next) && !vis.count(next)) { --cnt; if(cnt == 0) return true; Q.emplace(next); vis.insert(next); } } } return false; } bool solve(ll s, ll d) { int bound = 1e6; bool a = graphSearch(s, d, bound), b = graphSearch(d, s, bound); return a && b; } ll readBin() { string s; cin >> s; ll nr = 0; for(int i = N - 1; i >= 0; --i) if(s[i] == '1') nr += (1LL << (N - i - 1)); return nr; } void read() { cin >> N >> K; x = readBin(), y = readBin(); for(int i = 0; i < K; ++i) { ll a; a = readBin(); forbidden.insert(a); } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); read(); if(solve(x, y)) cout << "TAK"; else cout << "NIE"; }
#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...