#P10609. 排除干扰

    ID: 10003 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>贪心博弈论洛谷原创交互题Special JudgeO2优化洛谷月赛

排除干扰

Description

This is an interactive problem.

To analyze from both perspectives, Renko imagines a game between Little R and Little M, with the following rules:

Both Little R and Little M initially have mm cards, categorized into nn types numbered 11 to nn. Each type has at least one card initially for both players. They can see each other's cards.

They take turns discarding cards, with Little R going first. Each turn, they discard exactly one card. When both are left with one card each—suppose Little R's card is uu and Little M's is vv—Little R's score is au,va_{u,v}, and Little M's score is au,v-a_{u,v}. Both aim to maximize their own scores.

You will simulate a game with the interactor. If c=0c=0, you play as Little R; if c=1c=1, you play as Little M. Your score must meet or exceed the optimal score when both play optimally.

Input Format

  • The first line contains three integers nn, mm, cc, as described.
  • The next nn lines each contain nn integers, representing matrix aa. The ii-th row and jj-th column is ai,ja_{i,j}.
  • The next two lines each contain nn integers:
    • The first line: RiR_i denotes Little R's initial count of type ii cards.
    • The second line: MiM_i denotes Little M's initial count of type ii cards.
      It is guaranteed that Ri=Mi=m\sum R_i = \sum M_i = m.

Interaction Process:

  1. If it is the opponent's turn (interactor's move), read an integer xx, indicating they discarded a type xx card.
  2. If it is your turn, output an integer yy, indicating you discard a type yy card.
  3. If the game ends (both have one card left) and your score is suboptimal/your move is invalid, read -1 and exit.
  4. If the game ends and your score is optimal, read 0 and exit.

Note: After each output, flush the buffer. Common methods include:

  • C++: fflush(stdout) or cout.flush().
  • C: fflush(stdout).
  • Java: System.out.flush().
  • Python: stdout.flush().
  • Pascal: flush(output).
  • Others: Refer to documentation.

Output Format

Follow the interaction rules described above.

2 2 0
1 0
1 1
1 1
1 1

2
0





1
2 2 0
2 3
3 4
1 1
1 1

2
0





1

2 3 1
1 -2
-1 2
1 2
2 1
1

2

0







1

2

Hint

Explanation

Sample #1

You play as Little R (first to act). If you discard a type 11 card and the opponent discards type 22, your score is 11, which is optimal.
This sample satisfies Special Properties B and C.

Sample #2

As Little R, the optimal score is 33.
This sample satisfies Special Property A.

Sample #3

You play as Little M (second to act). The optimal score for Little M is 11.

Constraints

Bundled testing is used.

$$\def\arraystretch{1.5} \begin{array}{|c|c|c|c|c|c|}\hline \textbf{Subtask} & \textbf{Points} & \bm{n \leq} & \bm{m \leq} & \textbf{Special Property} & \textbf{Subtask Dependencies} \cr\hline 1 & 20 & 5 & 5 & - & - \cr\hline 2 & 15 & 10^3 & 10^4 & \mathbf{A} & - \cr\hline 3 & 20 & 10^3 & 10^4 & \mathbf{B} & - \cr\hline 4 & 20 & 10^3 & 10^3 & \mathbf{C} & - \cr\hline 5 & 25 & 10^3 & 10^4 & - & 1,2,3,4 \cr\hline \end{array}$$

Special Properties:

  • A: ai,j=i+ja_{i,j} = i + j.
  • B: aa contains only 00 and 11.
  • C: Each player initially has exactly one card per type.

For all data:
1n1031 \leq n \leq 10^3, 1m1041 \leq m \leq 10^4, ai,j108|a_{i,j}| \leq 10^8, 1Ri,Mim1 \leq R_i, M_i \leq m, Ri=Mi=m\sum R_i = \sum M_i = m. The interactor's moves are guaranteed valid.


Translated by DeepSeek R1