問題一覧 > 通常問題

No.334 Kadomatsu Game

レベル : / AI推定難易度 : 1025 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 143
作問者 : nmnmnmnmnmnmnm
お気に入りにしたユーザー ProblemId : 930 / 自分の提出
問題文最終更新日: 2026-06-25 10:55:05
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 129 (順位表) の他の問題:

Problem Statement

A Kadomatsu sequence is defined as follows: when 3 integers are arranged as A, B, C from the left,
they form a Kadomatsu sequence if all the values are distinct and the second largest integer among A, B, C is either A or C.

D and E play the Kadomatsu game using these Kadomatsu sequences.
Initially, N positive integers are arranged in a horizontal row.
First, among the N integers, choose the a-th integer X, the b-th integer Y, and the c-th integer Z from the left $(a \lt b \lt c)$.
If X, Y, Z form a Kadomatsu sequence, D can erase these 3 integers.
The 3 integers erased in this way cannot be used afterwards.
This operation is repeated in the same way alternately, with D moving first, in the order E, D, ...
In the Kadomatsu game, the player who cannot form a Kadomatsu sequence and thus cannot erase integers loses.

Both D and E make the best choices in order to win.
What first move should D, the first player, choose in order to win for certain?
Answer with the positions from the left of the three integers (0-indexed).
If there are multiple answers, output the lexicographically smallest one among them.
If D cannot win, output -1.

Input

$N$
$K_0\ K_1\ \dots\ K_{N-1}$

N is the number of positive integers. $3\le N \le 12$.
$K_i$ is the value of the i-th positive integer from the left. $1\le K_i \le 20$.

Output

When the lexicographically smallest first move with which D wins is the a-th, b-th, and c-th integers from the left $(a< b < c)$,
output the answer on one line in the form "a b c", with a half-width space between the numbers.
If D cannot win no matter what, output "-1" on one line.
Do not forget the newline at the end.

Sample

Sample 1
Input
6
2 3 5 7 4 1
Output
0 4 5

D first chooses the 0-th, 4-th, and 5-th integers from the left, "2, 4, 1".
Since "2, 4, 1" is a Kadomatsu sequence, these 3 integers are erased.
The remaining array is 3, 5, 7, from which E cannot form a Kadomatsu sequence.
Besides "0 4 5", A can also win with "1 4 5" and "2 3 5", but the lexicographically smallest is "0 4 5".

Sample 2
Input
5
1 2 3 4 5
Output
-1

No matter what D does at the start, D cannot form a Kadomatsu sequence and cannot erase integers.
Therefore, D has no winning choice, so output -1.

Sample 3
Input
12
5 1 13 10 12 12 12 3 9 13 17 18
Output
-1

D cannot win.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。