Logo
(追記) (追記ここまで)

13953번 - Invisible Integers 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
5 초 512 MB222100.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:

  • An arbitrary starting position is chosen in the hidden sequence.
  • An arbitrary direction is chosen — either left or right.
  • Starting from the chosen position we traverse all the integers of the hidden sequence in the chosen direction. We append the traversed integers to the end of the hint while skipping over the integers already in the hint.

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.

제한

예제 입력 1

5
1 2 0
3 4 0
1 4 3 0
3 1 4 2 0
1 2 4 3 0

예제 출력 1

7

예제 입력 2

3
1 2 0
2 3 0
3 4 0

예제 출력 2

-1

힌트

In the first example, (1, 2, 1, 4, 1, 3, 4) is one sequence of minimal length consistent with the given hints:

  • Hint (1, 2) can be obtained by starting from the 3rd element and heading left.
  • Hint (3, 4) can be obtained by starting from the 6th element and heading right.
  • Hint (1, 4, 3) can be obtained by starting from the 3rd element and heading right.
  • Hint (3, 1, 4, 2) can be obtained by starting from the 6th element and heading left.
  • Hint (1, 2, 4, 3) can be obtained by starting from the 1st element and heading right.

출처

ICPC > Regionals > Europe > Central European Regional Contest > CERC 2016 I번

Contest > Open Cup > 2016/2017 Season > Stage 8: Grand Prix of Europe I번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /