Submission #316605

# Submission time Handle Problem Language Result Execution time Memory
316605 2020-10-26T22:43:28 Z thecodingwizard Walk (POI13_spa) C++11
36 / 100
5000 ms 207132 KB
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int n, k; 
set<ll> dead;

ll read() {
    ll num = 0;
    for (int i = n-1; i >= 0; i--) {
        char c; cin >> c;
        if (c == '1') {
            num |= (1LL << i);
        } else {
            assert(c == '0');
        }
    }
    return num;
}

// return true if a can reach b or if a can reach at least ct nodes
bool solve(ll a, ll b, int ct) {
    set<ll> vis;
    queue<ll> q; q.push(a); vis.insert(a);
    while (!q.empty()) {
        ll u = q.front(); q.pop();
        for (int i = 0; i < n; i++) {
            ll v = u ^ (1LL << i);
            if (vis.count(v) || dead.count(v)) continue;
            vis.insert(v);
            if ((int)vis.size() >= ct || v == b) return true;
            q.push(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" << endl;
        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 2 ms 384 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 6 ms 512 KB Output is correct
4 Correct 60 ms 1152 KB Output is correct
5 Correct 28 ms 1144 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 176 ms 15316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 450 ms 12536 KB Output is correct
2 Correct 1049 ms 14436 KB Output is correct
3 Execution timed out 5085 ms 83504 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 118 ms 8056 KB Output is correct
3 Correct 277 ms 8056 KB Output is correct
4 Correct 59 ms 2560 KB Output is correct
5 Correct 26 ms 2680 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 512 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 115 ms 5728 KB Output is correct
4 Correct 465 ms 15100 KB Output is correct
5 Correct 189 ms 15228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 191 ms 6264 KB Output is correct
2 Execution timed out 5075 ms 207132 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 181 ms 5112 KB Output is correct
2 Correct 1224 ms 69256 KB Output is correct
3 Correct 3149 ms 69600 KB Output is correct
4 Execution timed out 5075 ms 189616 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 344 ms 10228 KB Output is correct
2 Execution timed out 5102 ms 108416 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 368 ms 9592 KB Output is correct
2 Correct 182 ms 4344 KB Output is correct
3 Execution timed out 5061 ms 93024 KB Time limit exceeded
4 Halted 0 ms 0 KB -