#include <bits/stdc++.h>
using namespace std;
const int VALMAX = (1 << 22) + 100;
bool sol;
int n, k, y;
bool f[VALMAX + 1];
void dfs(int node) {
int bit;
if (sol)
return;
f[node] = 1;
if (node == y)
sol = 1;
for (bit = 0; bit < n; bit++) {
int newnode = (node ^ (1 << bit));
if (f[newnode] == 0)
dfs(newnode);
}
}
int main() {
int i, j, x;
cin >> n >> k;
string s1, s2;
cin >> s1 >> s2;
x = y = 0;
for (i = n - 1; i >= 0; i--) {
x = 2 * x + (s1[i] - '0');
y = 2 * y + (s2[i] - '0');
}
for (i = 0; i < k; i++) {
string s;
cin >> s;
int val = 0;
for (j = n - 1; j >= 0; j--)
val = val * 2 + (s[j] - '0');
f[val] = 1;
}
if (x == y) {
cout << "TAK";
return 0;
}
dfs(x);
if (sol)
cout << "TAK";
else
cout << "NIE";
return 0;
}
# | 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... |