QOJ.ac

QOJ

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

#14433. 看错题

Statistiques

众所周知,想出新题目的最好方法就是读错题意。所以这里有一道通过这种方式创造出来的题目。

有 $m$ 个石头和它们在 $n$ 个盒子中的 $k$ 种分配方案。每种石头的分配方案都可以表示为一个非负整数数组 $a$,满足 $a_1 + \dots + a_n = m$。Alice 将构建一种石头的分配方案 $b$,并定义 $\text{cost}(b, a)$ 为将 $a$ 变为 $b$ 所需的最少操作次数,操作定义如下:

  • 从拥有正数个石头的盒子 $i$($1 \le i \le n$)中取出一个石头,放入盒子 $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\}$,我们有 $\text{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\}$,我们有 $\text{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\}$,我们有 $\text{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题解jiangly2025-12-14 07:27:04View

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.