#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
175 ms |
148088 KB |
Output is correct |
2 |
Correct |
92 ms |
148088 KB |
Output is correct |
3 |
Correct |
174 ms |
148084 KB |
Output is correct |
4 |
Correct |
177 ms |
148088 KB |
Output is correct |
5 |
Correct |
94 ms |
148088 KB |
Output is correct |
6 |
Correct |
11 ms |
16768 KB |
Output is correct |
7 |
Correct |
173 ms |
148036 KB |
Output is correct |
8 |
Correct |
178 ms |
148088 KB |
Output is correct |
9 |
Correct |
178 ms |
148216 KB |
Output is correct |
10 |
Correct |
94 ms |
148088 KB |
Output is correct |
11 |
Correct |
173 ms |
148088 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
285 ms |
148092 KB |
Output is correct |
2 |
Correct |
254 ms |
148728 KB |
Output is correct |
3 |
Correct |
960 ms |
152184 KB |
Output is correct |
4 |
Correct |
672 ms |
150900 KB |
Output is correct |
5 |
Correct |
679 ms |
150904 KB |
Output is correct |
6 |
Execution timed out |
5062 ms |
16768 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
179 ms |
148144 KB |
Output is correct |
2 |
Execution timed out |
5071 ms |
149580 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
178 ms |
148140 KB |
Output is correct |
2 |
Correct |
102 ms |
148088 KB |
Output is correct |
3 |
Execution timed out |
5074 ms |
148872 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
255 ms |
148088 KB |
Output is correct |
2 |
Execution timed out |
5084 ms |
148728 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
257 ms |
148220 KB |
Output is correct |
2 |
Execution timed out |
5034 ms |
149044 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
280 ms |
148092 KB |
Output is correct |
2 |
Execution timed out |
5043 ms |
151980 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
275 ms |
148224 KB |
Output is correct |
2 |
Correct |
386 ms |
148344 KB |
Output is correct |
3 |
Execution timed out |
5074 ms |
150296 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |