Submission #1218830

#TimeUsernameProblemLanguageResultExecution timeMemory
1218830KerimCop and Robber (BOI14_coprobber)C++20
0 / 100
1 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];

vector<vector<int>> E, G;

int start(int n, bool A[MAX_N][MAX_N]) {
    E.assign(n, {});
    G.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);
                G[j].push_back(i);
            }
        }
    }
    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] = sz(E[(k ? j : i)]);
        }
    }

    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
            if (!dp[x][y][tr]) {//if robber's move is loss
                for (auto j : G[x]) {
                    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 : G[x]) {
                    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 {
            if (!dp[x][y][tr]) {
                for (auto j : G[y]) {
                    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 : G[y]) {
                    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) return i;
    }

    return -1;
}

int nextMove(int R) {
    return -1;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...