QOJ.ac

QOJ

Límite de tiempo: 1 s Límite de memoria: 32 MB Puntuación total: 10

#11839. 体育俱乐部 [A]

Estadísticas

Byteland 最受欢迎的运动是 BitBall。Byteland 的许多城市每年都会组织 BitBall 联赛。每个 BitBall 球队都有权参加任意数量的联赛(无论联赛由谁组织)。赛季结束时,所有结果都会汇总。每个联赛都会发布自己的排名列表,对参加该联赛的球队进行排序。基于这些排名列表,《The best BitBaller》杂志决定并发布所有 BitBall 球队的超级排名列表。

确定超级排名列表并非易事。计算过程需要遵循以下假设:如果某支球队在包含 $l$ 个位置的排名列表中获得了第 $m$ 名,则该球队获得的分数为 $l + 1 - m$。如果该球队根本没有参加该联赛,则得 0 分。两个给定排名列表之间的距离计算如下:对于每支球队,我们计算其在两个列表中得分之差的绝对值,然后计算所有球队所得这些值的总和。需要确定的超级排名列表应满足其与所有排名列表的总距离最小。

编写一个程序,完成以下任务:

  • 从标准输入读取所有 BitBall 联赛的排名列表描述,
  • 为《The best BitBaller》杂志确定超级排名列表,
  • 将超级排名列表的总距离写入标准输出。

输入格式

标准输入的第一行包含两个整数 $n$ 和 $k$($2 \le n \le 500$,$1 \le k \le 500$),由单个空格分隔。它们分别代表球队数量和联赛数量。接下来的 $k$ 行描述了各个联赛。每个联赛的描述由一个整数 $m$($2 \le m \le n$)开始,表示该联赛中的球队数量,随后是 $m$ 个数字 $l_i$($1 \le l_i \le n$)。对于 $i \neq j$,没有两个数字 $l_i$ 和 $l_j$ 相等。数字 $l_i$ 表示排名列表中的第 $i$ 名由球队 $l_i$ 获得。行中的所有数字均由单个空格分隔。

输出格式

在标准输出的第一行,你的程序应写入一个整数,即超级排名列表的总距离(计算为与所有排名列表的距离之和)。

样例

输入格式 1

4 2
3 1 2 3
2 4 3

输出格式 1

11

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.