시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
5 초 | 512 MB | 2 | 2 | 2 | 100.000% |
Invisible integers is a simple game where the player tries to guess a hidden sequence of integers 1 through 9 given a number of hints. Each hint is a sequence of distinct integers generated as follows:
Find the length of the shortest hidden sequence consistent with the given hints.
The first line contains an integer n (1 ≤ n ≤ 10) — the number of hints. Each of the following n lines contains one hint. Each hint is a sequence of at least 1 and at most 9 distinct space-separated integers between 1 and 9 inclusive terminated with the integer 0.
If there is no solution output −1. Otherwise, output a single integer — the length of the shortest hidden sequence consistent with the given hints.
5 1 2 0 3 4 0 1 4 3 0 3 1 4 2 0 1 2 4 3 0
7
3 1 2 0 2 3 0 3 4 0
-1
In the first example, (1, 2, 1, 4, 1, 3, 4) is one sequence of minimal length consistent with the given hints: