Submission #339546

#TimeUsernameProblemLanguageResultExecution timeMemory
339546Alex_tz307Walk (POI13_spa)C++17
36 / 100
5106 ms183160 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 bound) { unordered_set<ll> vis; queue<ll> Q; int cnt = 1; Q.emplace(s); vis.insert(s); while(!Q.empty() && cnt < bound) { 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)) { Q.emplace(next); vis.insert(next); ++cnt; } } } if(cnt >= bound) return true; return false; } bool solve(ll s, ll d) { int bound = N * K + 1; 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...