#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
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")
|
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
600 KB |
Output is correct |
3 |
Correct |
1 ms |
600 KB |
Output is correct |
4 |
Correct |
7 ms |
1976 KB |
Output is correct |
5 |
Correct |
4 ms |
1624 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
49 ms |
11208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
110 ms |
16992 KB |
Output is correct |
2 |
Correct |
148 ms |
23420 KB |
Output is correct |
3 |
Runtime error |
3830 ms |
262144 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
42 ms |
12988 KB |
Output is correct |
3 |
Correct |
90 ms |
18596 KB |
Output is correct |
4 |
Correct |
17 ms |
4296 KB |
Output is correct |
5 |
Correct |
11 ms |
4584 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
856 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
62 ms |
14200 KB |
Output is correct |
4 |
Correct |
137 ms |
27360 KB |
Output is correct |
5 |
Correct |
98 ms |
24740 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
7580 KB |
Output is correct |
2 |
Correct |
2680 ms |
224160 KB |
Output is correct |
3 |
Runtime error |
3703 ms |
262144 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
56 ms |
7624 KB |
Output is correct |
2 |
Correct |
936 ms |
110724 KB |
Output is correct |
3 |
Correct |
2467 ms |
162280 KB |
Output is correct |
4 |
Correct |
4754 ms |
247044 KB |
Output is correct |
5 |
Correct |
2481 ms |
225856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
101 ms |
18548 KB |
Output is correct |
2 |
Correct |
3006 ms |
223436 KB |
Output is correct |
3 |
Runtime error |
3970 ms |
262144 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
123 ms |
18804 KB |
Output is correct |
2 |
Correct |
35 ms |
7980 KB |
Output is correct |
3 |
Correct |
4174 ms |
242784 KB |
Output is correct |
4 |
Correct |
57 ms |
10780 KB |
Output is correct |
5 |
Correct |
2483 ms |
222984 KB |
Output is correct |