Nine Knights | 프로그래밍의 벗 PivotOJ
PivotOJ

Nine Knights

시간 제한: 2000ms메모리 제한: 512MB출처: ICPC Mid-Central Regional 2017BOJ 15095
이 문제는 본문 이미지 일부가 표시되지 않습니다. 텍스트만으로 풀이가 어려울 수 있습니다.

문제

In the game of chess, knights are unique due to their “L-shaped” movement. A knight can move, as shown in Figure A.1, by either moving two squares sideways and one square up or down, or moving one square sideways and two squares either up or down.

[이미지 1]
Figure A.1: The highlighted squares show all possible moves for a knight.

In the Nine Knights puzzle, exactly nine knights must be positioned on a 5-by-5 board so that no knight can attack another knight with a single move. The configuration shown in Figure A.2 is an invalid solution because two of the knights can attack each other, where the configuration shown in Figure A.3 is a valid solution.

[이미지 2] [이미지 3]
Figure A.2: Invalid game configuration Figure A.3: Valid game configuration

Given the description of a game configuration, your job is to determine whether or not it represents a valid solution to the Nine Knights puzzle.

입력

The input will consist of 5 lines, each having 5 characters. All characters will be either ’k’, indicating the placement of a knight, or ’.’, indicating an empty space on the board.

출력

Display the word valid if the given chess board is a valid solution to the Nine Knights puzzle. Otherwise, display the word invalid.

예제

예제 1

입력
...k.
...k.
k.k..
.k.k.
k.k.k
출력
invalid

예제 2

입력
.....
...k.
k.k.k
.k.k.
k.k.k
출력
valid

예제 3

입력
.....
...k.
k.k.k
.k.k.
k...k
출력
invalid
코드를 제출하려면 로그인하세요.