# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1168326 | KaleemRazaSyed | Walk (POI13_spa) | C++20 | 0 ms | 0 KiB |
#include<bits/stdc++.h>
using namespace std;
#define int long long
int read()
{
string s;
cin >> s;
int res = 0;
for(char c : s)
res <<= 1, res += c - '0';
return res;
}
signed main()
{
int n, k;
cin >> n >> k;
int x = read(), y = read();
int a[k];
for(int i = 0; i < k; i ++)
a[i] = read();
sort(a, a + k);
queue<int> Q1, Q2;
bool poss = (x == y);
set<int> seen1, seen2;
Q1.push(x);
Q2.push(y);
while(Q1.size() && Q2.size() && !poss)
{
int u = Q1.front();
Q1.pop();
for(int i = 0; i < n; i ++)
{
int v = u ^ (1LL << i);
if(binary_search(a, a + k, v)) continue;
if(seen2.count(v))
poss = true;
else if(!seen1.count(v))
seen1.insert(v), Q1.push(v);
}
u = Q2.front();
Q2.pop();
for(int i = 0; i < n; i ++)
{
int v = u ^ (1LL << i);
if(binary_search(a, a + k, v)) continue;
if(seen1.count(v))
poss = true;
else if(!seen2.count(v))
seen2.insert(v), Q2.push(v);
}
}
cout << (poss ? "TAK" : "NIE") << endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
#define int long long
int read()
{
string s;
cin >> s;
int res = 0;
for(char c : s)
res <<= 1, res += c - '0';
return res;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int n, k;
cin >> n >> k;
int x = read(), y = read();
int a[k];
for(int i = 0; i < k; i ++)
a[i] = read();
bool poss = true;
int C[n + 1][n + 1];
for(int i = 1; i <= n; i ++)
{
C[i][i] = C[i][0] = 1;
for(int j = 1; j < i; j++)
C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
}
int cnt[n + 1] = {};
for(int i = 0; i < k; i ++)
cnt[__builtin_popcountll(x ^ a[i])]++;
int mx = __builtin_popcountll(x ^ y);
for(int i = 0; i < mx; i ++)
if(cnt[i] == C[n][i])
poss = false;
cout << (poss ? "TAK" : "NIE") << endl;
return 0;
}