This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#pragma GCC optimization("g", on)
#pragma GCC optimization("03")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse,-fgcse-lm")
#pragma GCC optimize("-ftree-pre,-ftree-vrp")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
ll n, k;
unordered_map<ll, bool> d;
ll read() {
string s; cin >> s;
ll x = 0;
for (int i = 0;i < n;i++) {
if (s[i] == '1') x += (1ll << i);
}
return x;
}
bool solve(ll x, ll y) {
ll cnt = min(n * k + 1, 2500000ll);
unordered_map<ll, bool> vis;
queue<ll> q;
q.push(x);
cnt--;
vis[x] = 1;
while (!q.empty()) {
ll v = q.front();
q.pop();
for (int i = 0;i < n;i++) {
ll t = v ^ (1ll << i);
if (t == y) return 1;
if (!vis[t] && !d[t]) {
cnt--;
if (!cnt) {
return 1;
}
vis[t] = 1;
q.push(t);
}
}
}
return 0;
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
cin >> n >> k;
ll x = read(), y = read();
for (int i = 1;i <= k;i++) {
ll t = read();
d[t] = 1;
}
cout << (solve(x, y) && solve(y, x) ? "TAK" : "NIE");
}
Compilation message (stderr)
spa.cpp:6: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
6 | #pragma GCC optimization("g", on)
|
spa.cpp:7: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
7 | #pragma GCC optimization("03")
|
spa.cpp:8: warning: ignoring '#pragma comment ' [-Wunknown-pragmas]
8 | #pragma comment(linker, "/stack:200000000")
|
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |