# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1116420 | biximo | Walk (POI13_spa) | C++17 | 100 ms | 17224 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int N = 300005, INF = 1000000000;
int n, k;
long long x, y;
set<long long> nt;
long long getNum(string s) {
long long v = 0;
for(char i: s) {
v = v*2+i-'0';
}
return v;
}
int getSz(long long st) {
queue<long long> que;
unordered_set<long long> vs;
que.push(st);
vs.insert(st);
while(que.size() && vs.size() <= 5000000) {
long long c =que.front(); que.pop();
for(int i = 0; i < n; i ++) {
if(c&1LL<<i) continue;
if(vs.count(c|1LL<<i)) continue;
if(nt.count(c|1LL<<i)) continue;
vs.insert(c|1LL<<i);
que.push(c|1LL<<i);
}
}
return vs.size();
}
bool contains(long long st, long long gl) {
queue<long long> que;
unordered_set<long long> vs;
que.push(st);
vs.insert(st);
while(que.size() && vs.size() <= 5000000) {
long long c =que.front(); que.pop();
for(int i = 0; i < n; i ++) {
if(c&1LL<<i) continue;
if(vs.count(c|1LL<<i)) continue;
if(nt.count(c|1LL<<i)) continue;
vs.insert(c|1LL<<i);
que.push(c|1LL<<i);
}
}
return vs.count(gl);
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> k;
string a, b;
cin >> a >> b; x = getNum(a); y = getNum(b);
while(k--) {
cin >> a;
nt.insert(getNum(a));
}
if(getSz(x) >= 5000000 && getSz(y) >= 5000000 || contains(x,y)) {
cout << "TAK\n";
} else {
cout << "NIE\n";
}
}
Compilation message (stderr)
# | 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... |