#P6738. [BalticOI 2014] Cop and Robber (Day1)

    ID: 5728 远端评测题 2000ms 256MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2014交互题Special JudgeO2优化BalticOI

[BalticOI 2014] Cop and Robber (Day1)

Description

A cop chases a robber. The cop will choose a street corner to guard. In each turn, the cop may choose to stay in place or move to an adjacent corner. The robber also starts at a street corner. Since he knows the map, he will choose the best strategy to move, but the robber is not allowed to stay in place.

In each round, the cop moves first, then the robber moves. There are two possible outcomes:

  1. The robber can avoid the cop forever.
  2. At some street corner, the robber and the cop meet, and the robber is arrested.

Determine whether the cop can catch the robber. If yes, output the minimum number of rounds.

Your code must assume that the robber plays with a winning strategy.

Interactive protocol

You need to implement two functions to interact with the interactor. Their prototypes are:

int start(int N, bool A[MAX_N][MAX_N]);
int nextMove(int R);
  • start(N, A) passes in the following parameters:

    • NN — the number of street corners (corners are numbered from 00 to N1N - 1).

    • AA — a 2D array describing the alleys: for all 0i,jN10 \le i,\,j \le N-1, if ii and jj are not connected, then A[i,j]=falseA[i,j]=\texttt{false}, otherwise A[i,j]=trueA[i,j]=\texttt{true}.

    All alleys are bidirectional (i.e. for all ii and jj, A[i,j]=A[j,i]A[i,j]=A[j,i]), and there are no self-loops (i.e. for all ii, A[i,i]=falseA[i,i]=\texttt{false}). In addition, you may assume that the cop can always reach any street corner from any other street corner through the alleys.

If the cop can catch the robber on the map described by the parameters, the function start should return the index of the street corner where the cop and robber will meet. Otherwise, return 1-1.

  • nextMove(R) is given the parameter RR, which is the index of the street corner where the robber is currently located. The function should return the index of the street corner where the cop is located after this move.

The function start will definitely be called once before the first call to nextMove. If start returns 1-1, then nextMove will not be called. Otherwise, nextMove will be called repeatedly until the chase ends. More precisely, the program must terminate as long as one of the following happens:

  • nextMove returns an illegal move.
  • The robber can avoid the cop forever.
  • The robber is caught.

Input Format

None

Output Format

None

Hint

Sample explanation

For sample 11, the graph is as shown below:

The function call process is as follows:

Function call Function return
start(4, [[0, 1, 1, 1], [1, 0, 0, 0], [1, 0, 0, 0], [1, 0, 0, 0]]) 3
nextMove(1)
nextMove(0) 0

Constraints and notes

This problem uses bundled testdata.

  • Subtask 1 (16 pts): No multiple edges.
  • Subtask 2 (14 pts): The map is grid-shaped, as follows:

  • Subtask 3 (30 pts): 2N1002 \le N \le 100.
  • Subtask 4 (40 pts): 2N2 \le N.

For 100%100\% of the data, 1N5001 \le N \le 500.

Thanks to the interactive library and SPJ author

https://www.luogu.com.cn/user/60864

This problem forces O2O2 optimization.

Notes

Translated from BalticOI 2014 Day1 A Cop and Robber.

Translated by ChatGPT 5