# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
32010 | kdh9949 | Walk (POI13_spa) | C++14 | 5000 ms | 262144 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;
typedef long long ll;
int n, k;
ll s, e;
unordered_set<ll> fb, ss;
queue<ll> q;
const int lim = 5000005;
ll get(){
char buf[62]; scanf("%s", buf);
ll ret = 0;
for(int i = n - 1, j = 0; i >= 0; i--, j++){
ret += (buf[i] - '0') * (1LL << j);
}
return ret;
}
int main(){
scanf("%d%d", &n, &k);
s = get(); e = get();
for(int i = 0; i < k; i++) fb.insert(get());
q.push(s); ss.insert(s);
while(!q.empty() && ss.size() < lim){
ll cur = q.front(); q.pop();
for(int i = 0; i < n; i++){
ll t = cur ^ (1LL << i);
if(ss.find(t) == ss.end() && fb.find(t) == fb.end()){
ss.insert(t);
q.push(t);
}
}
}
if(ss.find(e) != ss.end()){ puts("TAK"); return 0; }
if(ss.size() < lim){ puts("NIE"); return 0; }
ss.clear();
queue<ll>().swap(q);
q.push(e); ss.insert(e);
while(!q.empty() && ss.size() < lim){
ll cur = q.front(); q.pop();
for(int i = 0; i < n; i++){
ll t = cur ^ (1LL << i);
if(ss.find(t) == ss.end() && fb.find(t) == fb.end()){
ss.insert(t);
q.push(t);
}
}
}
puts(ss.size() == lim ? "TAK" : "NIE");
}
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... |