#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n, k;
set<ll> dead;
ll read() {
ll num = 0;
for (int i = n-1; i >= 0; i--) {
char c; cin >> c;
if (c == '1') {
num |= (1 << 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) {
set<ll> vis;
queue<ll> q; q.push(a); vis.insert(a);
while (!q.empty()) {
ll u = q.front(); q.pop();
for (int i = 0; i < n; i++) {
ll v = u ^ (1 << i);
if (vis.count(v) || dead.count(v)) continue;
vis.insert(v);
if ((int)vis.size() == ct || v == b) return true;
q.push(v);
}
}
return false;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> k;
ll a, b; a = read(), b = read();
for (int i = 0; i < k; i++) {
ll x = read();
dead.insert(x);
}
cout << (solve(a, b, n*k+1) && solve(b, a, n*k+1) ? "TAK" : "NIE") << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
512 KB |
Output is correct |
2 |
Correct |
3 ms |
512 KB |
Output is correct |
3 |
Correct |
6 ms |
512 KB |
Output is correct |
4 |
Correct |
58 ms |
1152 KB |
Output is correct |
5 |
Correct |
27 ms |
1152 KB |
Output is correct |
6 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
462 ms |
16452 KB |
Output is correct |
2 |
Correct |
1070 ms |
18168 KB |
Output is correct |
3 |
Execution timed out |
5067 ms |
87412 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
512 KB |
Output is correct |
2 |
Correct |
121 ms |
8184 KB |
Output is correct |
3 |
Correct |
279 ms |
8208 KB |
Output is correct |
4 |
Correct |
61 ms |
2680 KB |
Output is correct |
5 |
Correct |
28 ms |
2620 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1008 ms |
17308 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Incorrect |
90 ms |
5624 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5092 ms |
136888 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5094 ms |
123604 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
366 ms |
13944 KB |
Output is correct |
2 |
Execution timed out |
5077 ms |
117000 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
353 ms |
13688 KB |
Output is correct |
2 |
Correct |
181 ms |
6136 KB |
Output is correct |
3 |
Execution timed out |
5096 ms |
94700 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |