포럼
문제 ICPC00183

C. Connect the Dots

설명

A famous logical problem is that of connecting 9 dots on a paper by drawing 4 line segments with a pencil, while never lifting the pencil from the paper. While this is easy enough (although it requires some thinking outside of the box), Simone has recently been building a game called "Connect the Dots" around a generalisation of the concept.

In Connect the Dots, you are presented with a \(4 \times 4\) regular grid of dots. Each dot is given a unique number between \(1\) and \(16\). The task is then to connect the dots in order by their numbers, starting with dot \(1\) and ending with dot \(16\). The dots should be connected using as few line segments as possible, starting at dot \(1\), with the end of each segment being the start point of the next. The segments are allowed to intersect and overlap one another. Additionally, it is allowed to pass through other points while trying to connect the current point. This means, for example, that visiting the first four points in the order \(1, 4, 2, 3, 2, 4, \dots\) is acceptable. Formally, the sequence \(1, 2, \dots, 15, 16\) must be a subsequence of the sequence of dots visited.

Simone asked you to try the puzzle out, while betting you a balloon that it would be too hard. Prove her wrong by writing a program that solves the puzzle for you!

제약
입력 형식

The input consists of:
- \(4\) lines, each with \(4\) integers, the numbers of the dots in the grid. The \(j\)th number on the \(i\)th line is the number of the \(j\)th dot in the \(i\)th row of the grid of dots.

The \(16\) numbers in the input are all between \(1\) and \(16\) (inclusive) and pairwise distinct.

출력 형식

Output the minimum number of line segments needed to connect all the dots in order.

예제 1
입력
1 2 3 4
10 11 12 5
9 16 6 13
8 7 15 14
출력
6
예제 2
입력
1 2 3 4
8 9 10 11
7 15 16 12
6 14 13 5
출력
7
문제 정보

생성자가 기록되지 않았습니다.

출처 ICPC NWERC 2017

평가 및 의견

C. Connect the Dots

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 1 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

C. Connect the Dots

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8