問題一覧 > 通常問題

No.1060 Wonderful Treasure Chests

レベル : / AI推定難易度 : 1475 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 150
作問者 : Enjapma_kyopro / テスター : okuraofvegetabl
お気に入りにしたユーザー ProblemId : 4274 / 自分の提出
問題文最終更新日: 2020-05-22 20:37:55
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 249 (順位表) の他の問題:

Problem Statement

You and Enjapma decided to play a game together, just the $2$ of you.
The rules of the game are as follows.

  • $1$ . There are $N$ treasure chests on a desk. $N$ is even. Initially, all treasure chests are closed.
  • $2$ . Each treasure chest contains some gems. There are $M$ types of gems, and the $i$-th treasure chest contains $A_{ij}$ gems of the $j$-th type.
  • $3$ . The game is played with a first player and a second player. You are the first player, and Enjapma is the second player.
  • $4$ . The first and second players take turns choosing $1$ closed treasure chest, opening it, and obtaining all the gems inside. This is repeated until there are no closed treasure chests left.
  • $5$ . Each player's score, where $C_j$ is the number of gems of the $j$-th type that player has obtained, is given by ${C_1}^2 + {C_2}^2 + {C_3}^2 + ... + {C_M}^2$.

Let $X$ be your score and $Y$ be Enjapma's score at the end of the game.
If you play optimally to maximize the value of $X - Y$ and Enjapma plays optimally to minimize the value of $X-Y$, what will the final value of $X-Y$ be?
It can be proved that the absolute value of the answer does not exceed $10^{18}$ under these constraints.

Input

$N\ M$
$A_{11}\ A_{12}\ \dots\ A_{1M}$
$A_{21}\ A_{22}\ \dots\ A_{2M}$
$\vdots$
$A_{N1}\ A_{N2}\ \dots\ A_{NM}$

  • All inputs are integers.
  • $N$ is even.
  • $2 \le N \le 300$
  • $1 \le M \le 300$
  • $0 \le A_{ij} \le 100$

Output

Output the value of $X-Y$ when you use a strategy to maximize the value of $X - Y$ and Enjapma uses a strategy to minimize the value of $X-Y$.
Print a newline at the end.

Sample

Sample 1
Input
4 3
1 2 0
2 0 1
1 1 0
0 0 1
Output
5

You open the $1$st treasure chest, and Enjapma opens the $2$nd treasure chest.
Next, you open the $3$rd treasure chest, and Enjapma opens the $4$th treasure chest.
Your score is $2^2 + 3^2 + 0^2 = 13$, which is $13$ points.
Enjapma's score is $2^2 + 0^2 + 2^2 = 8$, which is $8$ points.

Sample 2
Input
2 4
2 0 2 0
0 5 2 2
Output
25

You open the $2$nd treasure chest, and Enjapma opens the $1$st treasure chest.
Your score is $0^2 + 5^2 + 2^2 + 2^2 = 33$, which is $33$ points.
Enjapma's score is $2^2 + 0^2 + 2^2 + 0^2 = 8$, which is $8$ points.

Sample 3
Input
4 3
0 0 0
0 0 0
0 0 0
0 0 0
Output
0

All the treasure chests were empty.

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