답안 #339546

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
339546 2020-12-25T15:46:20 Z Alex_tz307 Walk (POI13_spa) C++17
36 / 100
5000 ms 183160 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int N, K;
ll x, y;
unordered_set<ll> forbidden;

bool graphSearch(ll s, ll d, int bound) {
    unordered_set<ll> vis;
    queue<ll> Q;
    int cnt = 1;
    Q.emplace(s);
    vis.insert(s);
    while(!Q.empty() && cnt < bound) {
        ll v = Q.front();
        Q.pop();
        for(int i = 0; i < N; ++i) {
            ll next = v ^ (1LL << i);
            if(next == d)
                return true;
            if(!forbidden.count(next) && !vis.count(next)) {
                Q.emplace(next);
                vis.insert(next);
                ++cnt;
            }
        }
    }
    if(cnt >= bound)
        return true;
    return false;
}

bool solve(ll s, ll d) {
    int bound = N * K + 1;
    bool a = graphSearch(s, d, bound),
         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();
        forbidden.insert(a);
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    read();
    if(solve(x, y))
        cout << "TAK";
    else
        cout << "NIE";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 2 ms 492 KB Output is correct
3 Correct 3 ms 492 KB Output is correct
4 Correct 19 ms 1004 KB Output is correct
5 Correct 10 ms 1004 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 110 ms 9396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 177 ms 10676 KB Output is correct
2 Execution timed out 5069 ms 131492 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 97 ms 8388 KB Output is correct
3 Correct 159 ms 9048 KB Output is correct
4 Correct 34 ms 2704 KB Output is correct
5 Correct 18 ms 2552 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 492 KB Output is correct
2 Correct 48 ms 5136 KB Output is correct
3 Correct 92 ms 5680 KB Output is correct
4 Correct 398 ms 17004 KB Output is correct
5 Correct 188 ms 16712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 86 ms 5292 KB Output is correct
2 Execution timed out 5069 ms 183160 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 4496 KB Output is correct
2 Correct 1480 ms 67440 KB Output is correct
3 Correct 2849 ms 75344 KB Output is correct
4 Execution timed out 5088 ms 170248 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 145 ms 9012 KB Output is correct
2 Execution timed out 5106 ms 140668 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 148 ms 8628 KB Output is correct
2 Correct 2533 ms 83108 KB Output is correct
3 Execution timed out 5009 ms 83356 KB Time limit exceeded
4 Halted 0 ms 0 KB -