Submission #316628

# Submission time Handle Problem Language Result Execution time Memory
316628 2020-10-26T23:18:10 Z thecodingwizard Walk (POI13_spa) C++11
74 / 100
4530 ms 262148 KB
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int n, k; 
unordered_set<ll> dead;

ll read() {
    string s; cin >> s;
    ll num = 0;
    for (int i = n-1; i >= 0; i--) {
        if (s[n-1-i] == '1') {
            num |= (1LL << i);
        }
    }
    return num;
}

ll s[5000001];
unordered_set<ll> vis;
// return true if a can reach b or if a can reach at least ct nodes
bool solve(ll a, ll b, int ct) {
    vis.clear();
    int idx = 0;
    s[idx] = a;
    vis.insert(a);
    --ct;

    while (idx >= 0) {
        ll u = s[idx--];
        for (int i = 0; i < n; i++) {
            ll v = u ^ (1LL << i);
            if (vis.count(v) || dead.count(v)) continue;
            --ct;
            if (ct == 0 || v == b) return true;
            vis.insert(v);
            s[++idx] = v;
        }
    }
    return false;
}

int main() {
    cin.tie(0)->sync_with_stdio(0);

    cin >> n >> k;

    ll a, b; a = read(), b = read();
    if (a == b) {
        cout << "TAK\n";
        return 0;
    }
    for (int i = 0; i < k; i++) {
        ll x = read();
        dead.insert(x);
    }

    cout << (solve(a, b, n*k+1) && solve(b, a, n*k+1) ? "TAK" : "NIE") << endl;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 13 ms 1024 KB Output is correct
5 Correct 8 ms 1024 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 111 ms 9532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 209 ms 10784 KB Output is correct
2 Correct 457 ms 12864 KB Output is correct
3 Correct 3619 ms 184356 KB Output is correct
4 Correct 4530 ms 96948 KB Output is correct
5 Correct 4518 ms 96896 KB Output is correct
6 Correct 49 ms 4508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 43 ms 8484 KB Output is correct
3 Correct 80 ms 8500 KB Output is correct
4 Correct 14 ms 2444 KB Output is correct
5 Correct 9 ms 2444 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 512 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 46 ms 5276 KB Output is correct
4 Correct 216 ms 16572 KB Output is correct
5 Correct 121 ms 16576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 94 ms 5276 KB Output is correct
2 Runtime error 2716 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 91 ms 4508 KB Output is correct
2 Correct 817 ms 67544 KB Output is correct
3 Correct 1350 ms 67504 KB Output is correct
4 Correct 4377 ms 169916 KB Output is correct
5 Correct 2401 ms 170160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 181 ms 8764 KB Output is correct
2 Runtime error 2692 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 177 ms 8636 KB Output is correct
2 Correct 80 ms 4380 KB Output is correct
3 Correct 1762 ms 86320 KB Output is correct
4 Correct 3978 ms 177532 KB Output is correct
5 Correct 2124 ms 177580 KB Output is correct