제출 #1168194

#제출 시각아이디문제언어결과실행 시간메모리
1168194Ghulam_JunaidWalk (POI13_spa)C++20
0 / 100
0 ms328 KiB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int N = 61, K = 1e6 + 10;
int n, k, seen2;
ll X[2];
map<ll, bool> blocked;
map<ll, int> seen;

void bfs(){
    queue<int> q[2], nq[2];
    q[0].push(X[0]);
    seen[X[0]] = 1;
    q[1].push(X[1]);
    seen[X[1]] = 2;

    while (!q[0].empty() and !q[1].empty()){
        while (!q[0].empty()){
            int v = q[0].front();
            q[0].pop();

            for (int i = 0; i < n; i ++){
                int nv = (1ll << i) ^ v;
                if ((blocked[nv]) or seen[nv] == 1) continue;
                if (seen[nv] == 2) seen2 = 1;
                seen[nv] = 1;
                nq[0].push(nv);
            }
        }

        while (!q[1].empty()){
            int v = q[1].front();
            q[1].pop();

            for (int i = 0; i < n; i ++){
                int nv = (1ll << i) ^ v;
                if ((blocked[nv]) or seen[nv] == 2) continue;
                if (seen[nv] == 1) seen2 = 1;
                seen[nv] = 2;
                nq[1].push(nv);
            }
        }

        if (nq[0].size() >= k and nq[1].size() >= k) seen2 = 1;
        if (seen2) break;

        for (int i = 0; i < 2; i ++)
            while (!nq[i].empty())
                q[i].push(nq[i].front()), nq[i].pop();
    }
}

int main(){
    cin >> n >> k;
    for (int i = 0; i < 2; i ++){
        for (int j = 0; j < n; j ++){
            char c;
            cin >> c;
            X[i] = X[i] * 2 + (c - '0');
        }
    }
    if (X[0] > X[1]) swap(X[0], X[1]);

    if (X[0] == X[1]){
        cout << "TAK" << endl;
        return 0;
    }

    if ((X[0] & X[1]) != X[0]){
        cout << "NIE" << endl;
        return 0;
    }

    for (int i = 0; i < k; i ++){
        int cur = 0;
        for (int j = 0; j < n; j ++){
            char c;
            cin >> c;
            cur = cur * 2 + (c - '0');
        }
        blocked[cur] = 1;
    }

    bfs();
    if (seen2){
        cout << "TAK" << endl;
        return 0;
    }
    cout << "NIE" << endl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...