# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
339541 |
2020-12-25T15:37:18 Z |
Alex_tz307 |
Walk (POI13_spa) |
C++17 |
|
5000 ms |
120044 KB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int HSIZE = 5e6 + 11,
EMPTY = 0,
KMAX = 500009;
int N, K, fprev[KMAX], fhash[KMAX], vprev[HSIZE], vhash[HSIZE], vfree = 1, ffree = 1;
ll x, y, forbidden[KMAX], vis[HSIZE], Q[HSIZE];
void hashSetInsert(ll *S, int *prev, int *Hash, int &free, ll val, int sz) {
S[free] = val;
prev[free] = Hash[val % sz];
Hash[val % sz] = free++;
}
bool hashSetLookup(ll *S, int *prev, int *Hash, ll val, int sz) {
for(int i = Hash[val % sz]; i > 0; i = prev[i])
if(S[i] == val)
return true;
return false;
}
void hashSetClear(int *Hash, int &free, int sz) {
free = 1;
for(int i = 0; i < sz; ++i)
Hash[i] = 0;
}
bool graphSearch(ll s, ll d, int bound) {
int b = 0, e = 0, c = 1;
Q[e++] = s;
hashSetInsert(vis, vprev, vhash, vfree, s, HSIZE);
while(b < e && c < bound) {
ll v = Q[b++];
for(int i = 0; i < N; ++i) {
ll next = v ^ (1LL << i);
if(next == d)
return true;
if(!hashSetLookup(forbidden, fprev, fhash, next, KMAX) && !hashSetLookup(vis, vprev, vhash, next, HSIZE)) {
Q[e++] = next;
hashSetInsert(vis, vprev, vhash, vfree, next, HSIZE);
++c;
}
}
}
if(c >= bound)
return true;
return false;
}
bool solve(ll s, ll d) {
int bound = N * K + 1;
bool a = graphSearch(s, d, bound);
hashSetClear(vhash, vfree, HSIZE);
bool b = graphSearch(d, s, bound);
return a && b;
}
ll readBin() {
string s;
cin >> s;
ll nr = 0;
for(int i = N - 1; i >= 0; --i)
if(s[i] == '1')
nr += (1LL << (N - i - 1));
return nr;
}
void read() {
cin >> N >> K;
x = readBin(), y = readBin();
for(int i = 0; i < K; ++i) {
ll a;
a = readBin();
hashSetInsert(forbidden, fprev, fhash, ffree, a, KMAX);
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
read();
if(solve(x, y))
cout << "TAK";
else
cout << "NIE";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
20204 KB |
Output is correct |
2 |
Correct |
13 ms |
20076 KB |
Output is correct |
3 |
Correct |
14 ms |
20076 KB |
Output is correct |
4 |
Correct |
17 ms |
20332 KB |
Output is correct |
5 |
Correct |
14 ms |
20332 KB |
Output is correct |
6 |
Correct |
12 ms |
19948 KB |
Output is correct |
7 |
Correct |
12 ms |
19948 KB |
Output is correct |
8 |
Correct |
13 ms |
19948 KB |
Output is correct |
9 |
Correct |
13 ms |
19948 KB |
Output is correct |
10 |
Correct |
13 ms |
19948 KB |
Output is correct |
11 |
Correct |
74 ms |
29036 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
110 ms |
30060 KB |
Output is correct |
2 |
Correct |
2986 ms |
101276 KB |
Output is correct |
3 |
Execution timed out |
5049 ms |
101256 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
21868 KB |
Output is correct |
2 |
Correct |
37 ms |
24812 KB |
Output is correct |
3 |
Correct |
50 ms |
24940 KB |
Output is correct |
4 |
Correct |
25 ms |
22252 KB |
Output is correct |
5 |
Correct |
21 ms |
22252 KB |
Output is correct |
6 |
Correct |
13 ms |
20076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
22252 KB |
Output is correct |
2 |
Correct |
25 ms |
23660 KB |
Output is correct |
3 |
Correct |
38 ms |
23788 KB |
Output is correct |
4 |
Correct |
90 ms |
27500 KB |
Output is correct |
5 |
Correct |
56 ms |
27500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
79 ms |
28396 KB |
Output is correct |
2 |
Correct |
1679 ms |
120044 KB |
Output is correct |
3 |
Correct |
3237 ms |
119916 KB |
Output is correct |
4 |
Correct |
894 ms |
61292 KB |
Output is correct |
5 |
Correct |
493 ms |
61292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
77 ms |
28140 KB |
Output is correct |
2 |
Correct |
266 ms |
47676 KB |
Output is correct |
3 |
Correct |
480 ms |
47852 KB |
Output is correct |
4 |
Correct |
1753 ms |
92916 KB |
Output is correct |
5 |
Correct |
916 ms |
93036 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
97 ms |
29420 KB |
Output is correct |
2 |
Correct |
2509 ms |
115376 KB |
Output is correct |
3 |
Correct |
4198 ms |
115272 KB |
Output is correct |
4 |
Correct |
2249 ms |
79468 KB |
Output is correct |
5 |
Correct |
1188 ms |
79468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
109 ms |
29292 KB |
Output is correct |
2 |
Correct |
581 ms |
57964 KB |
Output is correct |
3 |
Correct |
1073 ms |
57964 KB |
Output is correct |
4 |
Correct |
71 ms |
27244 KB |
Output is correct |
5 |
Correct |
1694 ms |
96364 KB |
Output is correct |