CF887B.Cubes for Masha
普及-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Absent-minded Masha got set of n cubes for her birthday.
At each of 6 faces of each cube, there is exactly one digit from 0 to 9. Masha became interested what is the largest natural x such she can make using her new cubes all integers from 1 to x.
To make a number Masha can rotate her cubes and put them in a row. After that, she looks at upper faces of cubes from left to right and reads the number.
The number can't contain leading zeros. It's not required to use all cubes to build a number.
Pay attention: Masha can't make digit 6 from digit 9 and vice-versa using cube rotations.
健忘的玛莎生日时收到了一套 n 个立方体。
每个立方体的 6 个面上,各恰好印有一个从 0 到 9 的数字。玛莎开始好奇:她能用这些立方体表示从 1 到 x 的所有整数,其中最大的自然数 x 是多少?
要表示一个数字,玛莎可以旋转立方体,并将它们排成一行;然后她从左到右观察每个立方体朝上的面,读出该数字。
该数字不能包含前导零。构建一个数字时,不必使用全部立方体。
注意:玛莎不能通过旋转立方体将数字 6 变为 9,或将 9 变为 6。
输入格式
In first line integer n is given (1 ≤ n ≤ 3) — the number of cubes, Masha got for her birthday.
Each of next n lines contains 6 integers a__i__j (0 ≤ a__i__j ≤ 9) — number on j-th face of i-th cube.
第一行给出一个整数 n(1≤n≤3)——玛莎生日时得到的立方体数量。
接下来的 n 行中,每行包含 6 个整数 aij(0≤aij≤9)——第 i 个立方体的第 j 个面上的数字。
输出格式
Print single integer — maximum number x such Masha can make any integers from 1 to x using her cubes or 0 if Masha can't make even 1.
输出一个整数——即玛莎能用她的立方体拼出从 1 到 x 的所有整数时,x 的最大值;如果玛莎甚至无法拼出 1,则输出 0。
输入输出样例
输入#1
3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7
输出#1
87
输入#2
3 0 1 3 5 6 8 1 2 4 5 7 8 2 3 4 6 7 9
输出#2
98
说明/提示
In the first test case, Masha can build all numbers from 1 to 87, but she can't make 88 because there are no two cubes with digit 8.
在第一个测试用例中,玛莎可以构造从 1 到 87 的所有数字,但她无法构造 88,因为没有两个立方体上都带有数字 8。
输入解题思路,AI测评打分。不知道怎么写?