Submission #713338

# Submission time Handle Problem Language Result Execution time Memory
713338 2023-03-21T17:57:39 Z Stickfish Cop and Robber (BOI14_coprobber) C++17
0 / 100
1 ms 420 KB
#include "coprobber.h"
#include <iostream>
#include <cassert>
#include <bitset>
#include <vector>
using namespace std;

bitset<MAX_N> edg[MAX_N];
bitset<MAX_N> redg[MAX_N];
int bad_edg_cnt[2][MAX_N][MAX_N];
int depth[2][MAX_N][MAX_N];
int best_edg[MAX_N][MAX_N];
int n;
int C;
int pR = -1;

int start(int N, bool A[MAX_N][MAX_N]) {
    n = N;
    int deg[MAX_N];

    for (int i = 0; i < N; ++i) for (int j = 0; j < N; ++j) {
        edg[i][j] = redg[j][i] = A[i][j];
    }
    for (int i = 0; i < N; ++i)
        deg[i] = edg[i].count();
    for (int i = 0; i < N; ++i) for (int j = 0; j < N; ++j) {
        bad_edg_cnt[0][i][j] = 1;
        bad_edg_cnt[1][i][j] = deg[j];
    }
    vector<vector<int>> q;
    for (int i = 0; i < N; ++i) {
        bad_edg_cnt[0][i][i] = bad_edg_cnt[1][i][i] = 0;
        q.push_back({0, i, i});
        q.push_back({1, i, i});
    }
    int timer = 0;
    while (q.size()) {
        int t = q.back()[0];
        int u = q.back()[1];
        int v = q.back()[2];
        depth[t][u][v] = timer++;
        //cout << t << ' ' << u << ' ' << v << endl;
        q.pop_back();
        bitset<MAX_N> cedg;
        if (t == 0)
            cedg = redg[v];
        else {
            cedg = redg[u];
            //cedg[u] = 1;
        }
        for (int i = cedg._Find_first(); i < n; i = cedg._Find_next(i)) {
            int nu = u;
            int nv = v;
            if (t == 0) 
                nv = i;
            else
                nu = i;
            if (nu == nv)
                continue;
            if (--bad_edg_cnt[t ^ 1][nu][nv] == 0) {
                q.push_back({t ^ 1, nu, nv});
                if (t == 1)
                    best_edg[nu][nv] = u;
            }
        }
    }
    for (int u = 0; u < n; ++u) {
        for (int v = 0; v < n; ++v) {
            if (u == v || bad_edg_cnt[1][u][v] > 0)
                continue;
            for (int nv = edg[v]._Find_first(); nv < n; nv = edg[v]._Find_next(nv)) {
                assert(depth[0][u][nv] < depth[1][u][v]);
            }
            assert(bad_edg_cnt[1][u][v] >= 0);
        }
    }
    //for (int u = 0; u < n; ++u) {
        //for (int v = 0; v < n; ++v) {
            //if (bad_edg_cnt[1][u][v] <= 0) {
                //for (int nv = edg[v]._Find_first(); nv < n; nv = edg[v]._Find_next(nv)) {
                    //assert(bad_edg_cnt[0][u][nv] <= 0);
                //}
            //}
        //}
    //}

    for (int u = 0; u < n; ++u) {
        bool isok = true;
        for (int v = 0; v < n; ++v) {
            isok &= bad_edg_cnt[0][u][v] <= 0;
        }
        if (isok)
            return C = u;
    }
    return -1; 
}

int nextMove(int R) {
    assert(bad_edg_cnt[0][C][R] <= 0);
    if (pR != -1)
        assert(edg[pR][R]);
    pR = R;
    return best_edg[C][R];
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Incorrect 1 ms 420 KB the situation repeated
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 336 KB Cop can catch the robber, but start() returned -1
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Incorrect 0 ms 336 KB the situation repeated
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Incorrect 1 ms 420 KB the situation repeated
4 Halted 0 ms 0 KB -