Submission #316601

# Submission time Handle Problem Language Result Execution time Memory
316601 2020-10-26T22:28:33 Z thecodingwizard Walk (POI13_spa) C++11
12 / 100
5000 ms 206520 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 |= (1 << i);
        }
    }
    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();
    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 58 ms 1144 KB Output is correct
5 Correct 27 ms 1144 KB Output is correct
6 Incorrect 0 ms 384 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 472 ms 12408 KB Output is correct
2 Correct 1065 ms 14328 KB Output is correct
3 Execution timed out 5102 ms 83704 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 97 ms 3960 KB Output is correct
2 Correct 122 ms 8056 KB Output is correct
3 Correct 278 ms 8068 KB Output is correct
4 Correct 59 ms 2680 KB Output is correct
5 Correct 27 ms 2688 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 438 ms 16892 KB Output is correct
2 Incorrect 125 ms 5752 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5099 ms 174768 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5108 ms 206520 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 377 ms 10104 KB Output is correct
2 Execution timed out 5070 ms 111108 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 357 ms 9552 KB Output is correct
2 Correct 186 ms 4344 KB Output is correct
3 Execution timed out 5077 ms 93032 KB Time limit exceeded
4 Halted 0 ms 0 KB -