# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1168058 | Rafiullah | Walk (POI13_spa) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>j
#define fi first
#define se second
#define bupo __builtin_popcount
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define int long long
const int LOG = 16, MAXB = 1<<LOG, SQR = 1<<10;
const ll MOD = 1e9+7;
const int mod = 998244353;
const int N = 1e6 + 5;
int is_[N], n , k;
int is[N];
int t(string S){
int E = 0;
for(int i = n - 1 ; i >= 0 ; i --)E += (1LL << i) * (S[i] == '1');
return E;
}
void f(int num){
if(is_[num])return;
is[num] = 1;
for(int i = 0 ; i < n ; i ++)
if(!is[(num ^ (1LL << i))])
f((num ^ (1LL << i)));
}
void solve()
{
cin >> n >> k;
string a,b;cin >> a >> b;
int A = t(a);int B = t(b);
for(int i = 0 ; i < k ; i ++){
cin >> a;
is_[t(a)] = 1;
}
f(A);
if(is[B])cout << "TAK" << '\n';
else cout << "NIE" << '\n';
}
signed main(){
int t = 1;
// cin >> t;
while(t--)
solve();
}