이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "coprobber.h"
#include <vector>
struct State
{
State(int c, int r, int p) : posCop(c), posRob(r), player(p) {}
int posCop, posRob, player;
};
const int MAXN = 500;
int nodeDeg[MAXN];
int degree[MAXN][MAXN][2];
std::vector<State> rm;
bool copWin[MAXN][MAXN][2];
int go[MAXN][MAXN];
int posCop = -1;
void process(int cop, int robber, int player, int from)
{
if (!copWin[cop][robber][player])
{
if (player == 0)
go[cop][robber] = from;
copWin[cop][robber][player] = true;
rm.emplace_back(cop, robber, player);
}
}
int start(int N, bool A[MAX_N][MAX_N])
{
for (int iNode = 0; iNode < N; iNode++)
for (int jNode = 0; jNode < N; jNode++)
nodeDeg[iNode] += A[iNode][jNode];
for (int iCop = 0; iCop < N; iCop++)
for (int iRobber = 0; iRobber < N; iRobber++)
{
go[iCop][iRobber] = -1;
degree[iCop][iRobber][0] = nodeDeg[iCop] + 1;
degree[iCop][iRobber][1] = nodeDeg[iRobber];
}
for (int iNode = 0; iNode < N; iNode++)
process(iNode, iNode, 1, -1);
while (!rm.empty())
{
int cop = rm.back().posCop;
int robber = rm.back().posRob;
int player = rm.back().player;
rm.pop_back();
if (player == 1)
process(cop, robber, 0, cop);
for (int iEsc = 0; iEsc < N; iEsc++)
{
if (player == 1 && A[cop][iEsc])
process(iEsc, robber, 0, cop);
if (player == 0 && A[robber][iEsc])
{
degree[cop][iEsc][1]--;
if (degree[cop][iEsc][1] == 0)
process(cop, iEsc, 1, -1);
}
}
}
for (int iCop = 0; iCop < N; iCop++)
{
bool isWinner = true;
for (int iRobber = 0; iRobber < N; iRobber++)
isWinner &= copWin[iCop][iRobber][0];
if (isWinner)
{
posCop = iCop;
return iCop;
}
}
return -1;
}
int nextMove(int R)
{
int next = go[posCop][R];
posCop = next;
return next;
}
# | 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... |