QOJ.ac

QOJ

Time Limit: 10 s - 40 s Memory Limit: 1024 MB Total points: 25

#12286. 骰子顺子

Statistics

你拥有一套特殊的 $N$ 个六面骰子,每个骰子的六个面上各有一个不同的正整数。不同的骰子可能具有不同的数字组合。

你想要将部分或全部骰子排成一行,使得顶面上的数字构成一个顺子(即它们显示连续的整数)。对于每个骰子,你可以选择哪一个面朝上。

通过这种方式可以形成的最长顺子长度是多少?

输入格式

输入的第一行包含测试用例的数量 $T$。接下来是 $T$ 个测试用例。每个测试用例的第一行包含骰子的数量 $N$。接下来的 $N$ 行,每行包含六个正整数 $D_{ij}$。第 $i$ 行的第 $j$ 个数字表示第 $i$ 个骰子的第 $j$ 个面上的数字。

输出格式

对于每个测试用例,输出一行 Case #x: y,其中 $x$ 是测试用例编号(从 1 开始),$y$ 是可以形成的最长顺子的长度。

数据范围

$1 \le T \le 100$ $1 \le D_{ij} \le 10^6$ 对于所有 $i, j$。

子任务 1

时间限制:10 秒 $1 \le N \le 100$

子任务 2

时间限制:40 秒 $1 \le N \le 50000$ 所有测试用例的 $N$ 之和 $\le 200000$

样例

样例输入 1

3
4
4 8 15 16 23 42
8 6 7 5 30 9
1 2 3 4 55 6
2 10 18 36 54 86
2
1 2 3 4 5 6
60 50 40 30 20 10
3
1 2 3 4 5 6
1 2 3 4 5 6
1 4 2 6 5 3

样例输出 1

Case #1: 4
Case #2: 1
Case #3: 3

说明

在样例 #1 中,可以通过取第四个骰子的 2、第三个骰子的 3、第一个骰子的 4 以及第二个骰子的 5 来形成长度为 4 的顺子。

在样例 #2 中,无法形成比长度为 1 的平凡顺子更长的顺子。

在样例 #3 中,你可以从一个骰子取 1,从另一个取 2,从剩下的未使用骰子取 3。请注意,此样例展示了可能存在多个骰子具有相同面值集合的情况。

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.