Universal Cup Judging System

Universal Cup

Limite de temps : 3.0 s Limite de mémoire : 256 MB Points totaux : 100 Hackable ✓
Statistiques

眾所周知,想出新題目的最好方法就是讀錯題意。所以這裡有一道透過這種方式創造出來的題目。

有 $m$ 顆石頭以及它們在 $n$ 個盒子中的 $k$ 種分配方案。每種石頭的分配方案都可以表示為一個非負整數陣列 $a$,滿足 $a_1 + \dots + a_n = m$。Alice 將構造一種石頭的分配方案 $b$,並定義 $\operatorname{cost}(b, a)$ 為將 $a$ 變為 $b$ 所需的最少操作次數,操作定義如下:

  • 從裝有正數顆石頭的盒子 $i$($1 \le i \le n$)中取出 $1$ 顆石頭,放入盒子 $j$($1 \le j \le n$)中。

她希望找到一個最佳的分配方案 $b$,使得 $b$ 到所有給定分配方案的代價總和最小。

輸入格式

第一行包含 $3$ 個整數 $n, m, k$($1 \le n, k \le 400, 1 \le m \le 10^9$)—— 分別表示盒子數量、石頭數量和分配方案數量。

接下來的 $k$ 行,每行包含 $n$ 個非負整數 $a_{i,j}$($a_{i,1} + \dots + a_{i,n} = m$)—— 表示各個分配方案的描述。

輸出格式

輸出一個整數 —— 問題的答案。

範例

範例輸入 1

5 12 3
3 0 4 1 4
5 2 3 1 1
1 2 3 5 1

範例輸出 1

8

範例輸入 2

1 1 2
1
1

範例輸出 2

0

說明

對於第一個範例,一種可能的最佳分配方案為 $b = \{3, 2, 3, 2, 2\}$。對於這個分配方案 $b$,我們有:

  • 對於 $a = \{3, 0, 4, 1, 4\}$,我們有 $\operatorname{cost}(b, a) = 3$,因為我們可以按以下順序進行操作:$\{3, 0, 4, 1, 4\} \to \{3, 1, 4, 1, 3\} \to \{3, 2, 4, 1, 2\} \to \{3, 2, 3, 2, 2\}$。
  • 對於 $a = \{5, 2, 3, 1, 1\}$,我們有 $\operatorname{cost}(b, a) = 2$,因為我們可以按以下順序進行操作:$\{5, 2, 3, 1, 1\} \to \{4, 2, 3, 1, 2\} \to \{3, 2, 3, 2, 2\}$。
  • 對於 $a = \{1, 2, 3, 5, 1\}$,我們有 $\operatorname{cost}(b, a) = 3$,因為我們可以按以下順序進行操作:$\{1, 2, 3, 5, 1\} \to \{1, 2, 3, 4, 2\} \to \{2, 2, 3, 3, 2\} \to \{3, 2, 3, 2, 2\}$。

因此代價總和為 $8$。可以證明不可能獲得更小的代價總和。

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#371EditorialOpen题解jianglyView

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.