This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "coprobber.h"
#include <bits/stdc++.h>
using namespace std;
struct State {
int cop, robber;
bool turn; // 1 = cop
State(int c = -1, int r = -1, bool t = -1) : cop(c), robber(r), turn(t) {}
operator int() const { return 2 * (MAX_N * cop + robber) + turn; }
};
vector<State> graph[3 * MAX_N * MAX_N];
bool win[3 * MAX_N * MAX_N];
int deg_in[3 * MAX_N * MAX_N];
State here, nxt[3 * MAX_N * MAX_N], states[3 * MAX_N * MAX_N];
void add_edge(int a, int b, int c, int d, bool cop) {
graph[State(c, d, !cop)].push_back(State(a, b, cop));
deg_in[State(a, b, cop)]++;
}
int start(int N, bool A[MAX_N][MAX_N]) {
for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) {
if (i == j) continue;
add_edge(i, j, i, j, 1);
for (int k = 0; k < N; k++) if (A[i][k]) {
add_edge(i, j, k, j, 1);
add_edge(j, i, j, k, 0);
}
}
queue<State> q; // Reverse BFS
for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) for (int k = 0; k < 2; k++) {
if (!deg_in[State(i, j, k)]) {
q.push(State(i, j, k));
win[State(i, j, k)] = true;
}
}
while (q.size()) {
State curr = q.front();
q.pop();
for (State i : graph[curr]) {
deg_in[i]--;
if (!win[i] && (i.turn || !deg_in[i])) {
nxt[i] = curr;
win[i] = true;
q.push(i);
}
}
}
for (int i = 0; i < N; i++) {
bool guarantee = true;
for (int j = 0; j < N; j++) guarantee &= win[State(i, j, 1)];
if (guarantee) {
here = {i, i, 1};
return i;
}
}
return -1;
}
int nextMove(int R) {
here.robber = R;
here.turn = 1;
here = nxt[here];
return here.cop;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |