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;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef pair<int, int> ii;
bool mat[MAX_N + 5][MAX_N + 5];
bool win[MAX_N + 5][MAX_N + 5][2];
int deg[MAX_N + 5][MAX_N + 5][2];
int mv[MAX_N + 5][MAX_N + 5];
int n;
int last_pos;
int start(int N, bool A[MAX_N][MAX_N]) {
n = N;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
mat[i][j] = A[i][j];
memset(win, false, sizeof win);
queue<pair<ii, int> > q;
for (int i = 0; i < n; i++) {
win[i][i][0] = win[i][i][1] = true;
q.push(mp(mp(i, i), 0));
q.push(mp(mp(i, i), 1));
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
deg[i][j][0] = 0;
for (int nxt = 0; nxt < n; nxt++) {
if (mat[i][nxt])
deg[i][j][0]++;
}
deg[i][j][1] = 1;
for (int nxt = 0; nxt < n; nxt++) {
if (mat[j][nxt])
deg[i][j][1]++;
}
}
}
while (!q.empty()) {
int u = q.front().fi.fi;
int v = q.front().fi.se;
int who = q.front().se;
q.pop();
if (who == 1) {
for (int i = 0; i < n; i++) {
if (mat[u][i]) {
if (win[i][v][0]) continue;
deg[i][v][0]--;
if (deg[i][v][0] == 0) {
win[i][v][0] = true;
q.push(mp(mp(i, v), 0));
}
}
}
} else {
for (int j = 0; j < n; j++) {
if (mat[v][j] || v == j) {
if (win[u][j][1]) continue;
mv[u][j] = v;
win[u][j][1] = true;
q.push(mp(mp(u, j), 1));
}
}
}
}
int pos = -1;
for (int i = 0; i < n; i++) {
bool yes = true;
for (int j = 0; j < n; j++)
yes &= win[j][i][1];
if (yes) pos = i;
}
last_pos = pos;
return pos;
}
int nextMove(int R) {
return last_pos = mv[R][last_pos];
}
# | 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... |