問題一覧 > 通常問題

No.3674 Zero Sum Game

レベル : / 実行時間制限 : 1ケース 3.000秒 / メモリ制限 : 1024 MB / 小数誤差許容問題 絶対誤差または相対誤差が $10^{-6}$ 以下。ただし、ジャッジ側の都合で500桁未満にしてください
タグ : (AC するまで非表示) / 解いたユーザー数 3
作問者 : 👑 みうね / テスター : harurun TKTYI
お気に入りにしたユーザー ProblemId : 13836 / 自分の提出
問題文最終更新日: 2026-09-03 22:50:22
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 512 BONSAI (順位表) の他の問題:

Problem Statement

Alice has $N$ kinds of actions and Bob has $M$ kinds of actions. When Alice chooses action $i\ (1 \leq i \leq N)$ and Bob chooses action $j\ (1 \leq j \leq M)$, the score is $A_{i,j}$. Here, $A_{i,j}$ may be negative.

The game proceeds as follows.

  1. Alice decides the probability of choosing each of her actions (a probability distribution).
  2. Bob, knowing the probability distribution Alice decided on, decides the probability of choosing each of his actions.
  3. Each player chooses $1$ action according to their own probability distribution, independently of each other.

Letting $p_i$ be the probability that Alice chooses action $i$ and $q_j$ be the probability that Bob chooses action $j$, the expected value of the score is

$$\sum_{i=1}^{N}\sum_{j=1}^{M}p_iq_jA_{i,j}$$

where $p_i, q_j \geq 0$, $\sum_{i=1}^{N} p_i = 1$, and $\sum_{j=1}^{M} q_j = 1$.

Alice tries to maximize the expected score, and Bob tries to minimize the expected score. Find the expected score when Alice chooses an optimal probability distribution and Bob chooses an optimal probability distribution in response to it, that is,

$$ \max_{\substack{p_i\geq0\\\sum_{i=1}^{N} p_i=1}} \min_{\substack{q_j\geq0\\\sum_{j=1}^{M} q_j=1}} \sum_{i=1}^{N}\sum_{j=1}^{M}p_iq_jA_{i,j} $$

.

You are given $T$ test cases; find the answer for each of them.
Note: except for the samples, the values $A_{i,j}$ of each test case are randomly generated. See the "Input Generation" section for details.

Input

The input is given from Standard Input in the following format.

$T$
$\mathrm{case}_1$
$\mathrm{case}_2$
$\vdots$
$\mathrm{case}_T$

$\mathrm{case}_k$ represents the $k$-th test case and is in the following format.

$N\ M$
$A_{1,1}\ A_{1,2}\ \ldots\ A_{1,M}$
$A_{2,1}\ A_{2,2}\ \ldots\ A_{2,M}$
$\vdots$
$A_{N,1}\ A_{N,2}\ \ldots\ A_{N,M}$

Constraints

  • $1\leq T\leq 20$
  • $1\leq N,M\leq 200$
  • The sum of $N\times M$ over all test cases in $1$ input is at most $200000$
  • $-10000\leq A_{i,j}\leq 10000$
  • All input values are integers

Input Generation

$T$ and the values $N, M$ of each test case are set within the constraints.
In test cases other than the samples, each $A_{i,j}$ is chosen independently and uniformly at random from the integer interval $[-10000, 10000]$.
The test cases used by the judge are fixed.

Output

Output $T$ lines. On the $k$-th line, output the expected score for the $k$-th test case when both players choose optimal probability distributions.

The reference value held by the judge is guaranteed to have an absolute error of at most $10^{-10}$ from the true value.

Your output is judged correct if its absolute or relative error from the reference value is at most $10^{-6}$.

Print a newline at the end of the output.

Sample

Sample 1
Input
3
1 1
3
2 2
1 -1
-1 1
2 2
-1 -4
-3 -2
Output
3.0
0.0
-2.5

In the 1st test case, both players have only $1$ action available, so the score is always $3$.

In the 2nd test case, if Alice chooses each action with probability $1/2$, the expected score is $0$ whichever action Bob chooses. On the other hand, if Alice chooses one of the actions with probability greater than $1/2$, Bob (who knows Alice's probability distribution) can choose an action that makes the expected score negative. Therefore, the expected score when both players choose optimal probability distributions is $0$.

In the 3rd test case, if Alice chooses action 1 with probability $1/4$ and action 2 with probability $3/4$, the expected score is $-5/2$ whichever action Bob chooses. On the other hand, if Bob chooses each of actions 1 and 2 with probability $1/2$, the expected score is $-5/2$ whichever action Alice chooses. Thus, whatever probability distribution Alice chooses, Bob can make the expected score at most $-5/2$. Therefore, the expected score when both players choose optimal probability distributions is $-5/2$.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。