Submission #1220185

#TimeUsernameProblemLanguageResultExecution timeMemory
1220185stdfloatCop and Robber (BOI14_coprobber)C++20
0 / 100
2 ms2376 KiB
#include <bits/stdc++.h>
#include "coprobber.h"
// #include "grader.cpp"
using namespace std;

#define sz(v)   (int)(v).size()

int dp[501][501][2], cnt[501][501][2];

int P = -1;

vector<vector<int>> E;

int start(int n, bool A[MAX_N][MAX_N]) {
    E.assign(n, {});
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++)
            if (A[i][j]) E[i].push_back(j);
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            for (int k = 0; k < 2; k++)
                cnt[i][j][k] = (k ? sz(E[j]) : sz(E[i]) + 1);
        }
    }

    memset(dp, -1, sizeof dp);

    queue<pair<pair<int, int>, bool>> q;
    for (int i = 0; i < n; i++) {
        dp[i][i][0] = 1;
        dp[i][i][1] = 0;
        q.push({{i, i}, false});
        q.push({{i, i}, true});
    }

    while (!q.empty()) {
        auto [d, tr] = q.front(); q.pop();
        auto [x, y] = d;

        if (tr) { //robber's move
            vector<int> police = E[x]; //police moves
            police.push_back(x);
            if (!dp[x][y][tr]) {//if robber's move is loss
                for (auto j : police) {
                    if (~dp[j][y][tr^1]) assert(dp[j][y][tr^1]);
                    else {
                        dp[j][y][tr^1] = 1;
                        q.push({{j, y}, tr^1});
                    }
                }
            }
            else {//if robber's move is win
                for (auto j : police) {
                    if (~dp[j][y][tr^1]) continue;

                    if (!--cnt[j][y][tr^1]) {
                        dp[j][y][tr^1] = 0;
                        q.push({{j, y}, tr^1});
                    }
                }
            }
        }
        else {
            vector<int> robber = E[y]; //robbers moves
            if (!dp[x][y][tr]) {
                for (auto j : robber) {
                    if (~dp[x][j][tr^1]) assert(dp[j][y][tr^1]);
                    else {
                        dp[x][j][tr^1] = 1;
                        q.push({{x, j}, tr^1});
                    }
                }
            }
            else {
                for (auto j : robber) {
                    if (~dp[x][j][tr^1]) continue;

                    if (!--cnt[x][j][tr^1]) {
                        dp[x][j][tr^1] = 0;
                        q.push({{x, j}, tr^1});
                    }
                }
            }
        }
    }

    for (int i = 0; i < n; i++) {
        bool tr = true;
        for (int j = 0; j < n && tr; j++)
            tr = dp[i][j][0] == 1;

        if (tr){
            P = i; break;
        }
    }

    return P;
}

int nextMove(int R) {
    assert(dp[P][R][0]);
    vector<int> police = E[P];
    police.push_back(P);
    for (auto to : police) {
        if (!dp[to][R][1]){
            P = to; break;
        }
    }

    return P;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...