| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 1 초 | 1024 MB | 34 | 8 | 7 | 25.000% |
Five in a Row, also called Gomoku, is a board game played with Go pieces (black and white stones). The winner is the first player to form an unbroken line of five stones of their color horizontally, vertically, or diagonally.
During leisure time at the Olympics, athletes and coaches also enjoy playing this game for recreation. Nevertheless, today they are playing a more advanced version in a $K$-dimensional board instead of a traditional $2$-dimensional board. Stones A, B, C, D, E are considered as five in a row if, for every integer $i$ such that $1 \le i \le K$, we have:
$A[i] - B[i] = B[i] - C[i] = C[i] - D[i] = D[i] - E[i] =$ one of $\{-1, 0, 1\}$.
Here, $A[i]$ is the coordinate of the stone $A$ on the $i$th dimension.
Due to the complexity of the board, they sometimes get overwhelmed. Therefore you are asked to write a referee program that takes all the moves made by one player in chronological order and calculates after placing which stone we see five in a row for the first time.
The first line contains two space-separated integers $K$ and $N$: $K$ is the number of dimensions of the board, and $N$ is the number of stones. This line is followed by $N$ lines, which describe the $N$ stones placed by one player in chronological order. The $i$th such line contains $K$ space-separated integers $x_1, x_2, \dots , x_K$, which are the $K$ coordinates of the $i$th stone.
The output should contain a single line. This line must contain the smallest positive integer $i$ for which we see five in a row after placing the $i$th stone; or NOT ALIGNED if such an integer $i$ does not exist.
4 9 5 5 5 5 5 5 4 6 5 5 3 7 5 5 2 8 6 6 6 6 9 9 9 9 7 7 7 7 5 5 1 9 8 8 8 8
8
After placing the $8$th stone, we see the following five in a row:
Actually, after placing the $9$th stone, we see another five in a row:
As the $8$th stone was put first, we output $8$.
3 6 0 0 0 1 0 0 2 0 0 3 0 0 3 1 0 3 2 0
NOT ALIGNED