#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int N, K;
ll x, y;
unordered_set<ll> vis, forbidden;
queue<ll> Q;
bool graphSearch(ll s, ll d, int bound) {
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);
vis.clear();
bool 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";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
2 ms |
492 KB |
Output is correct |
3 |
Correct |
3 ms |
492 KB |
Output is correct |
4 |
Correct |
19 ms |
1004 KB |
Output is correct |
5 |
Correct |
10 ms |
1004 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
2 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
112 ms |
9652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
197 ms |
10932 KB |
Output is correct |
2 |
Execution timed out |
5105 ms |
131956 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
492 KB |
Output is correct |
2 |
Incorrect |
124 ms |
9268 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
876 KB |
Output is correct |
2 |
Correct |
49 ms |
5264 KB |
Output is correct |
3 |
Correct |
81 ms |
6032 KB |
Output is correct |
4 |
Correct |
313 ms |
17372 KB |
Output is correct |
5 |
Incorrect |
305 ms |
17500 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
86 ms |
5528 KB |
Output is correct |
2 |
Execution timed out |
5108 ms |
182864 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
78 ms |
4752 KB |
Output is correct |
2 |
Incorrect |
2169 ms |
76704 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
143 ms |
9140 KB |
Output is correct |
2 |
Execution timed out |
5095 ms |
139996 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
146 ms |
8884 KB |
Output is correct |
2 |
Correct |
2502 ms |
83708 KB |
Output is correct |
3 |
Correct |
3969 ms |
94612 KB |
Output is correct |
4 |
Correct |
97 ms |
7824 KB |
Output is correct |
5 |
Execution timed out |
5087 ms |
157120 KB |
Time limit exceeded |