問題一覧 > 通常問題

No.531 The Peace Accord of Nsukumi Island

レベル : / AI推定難易度 : 800 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 374
作問者 : はむこ / テスター : Nafmo2
お気に入りにしたユーザー ProblemId : 1472 / 自分の提出
問題文最終更新日: 2026-06-26 06:08:01
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 167 (順位表) の他の問題:

Problem Statement

On Nsukumi Island, peace is maintained by a peculiar ecosystem.

・$n$ animals live there.
・Animal $i$ can prey on animal $i+1$ ($1 \le i \le n-1$).
・Animal $n$ can prey on animal $1$.

Since the animals do not want to be preyed upon, they have made an arrangement that acts as a mutual deterrent.
That is, they have agreed to always maintain a situation in which every animal, if it is a predator, is also prey.

Now, the animals of Nsukumi Island are considering moving to New Nsukumi Island.
The move is carried out using $n$ boats, each carrying at most $m$ animals, according to the following procedure.
・All boats are initially at Nsukumi Island.
・A boat can travel between Nsukumi Island and New Nsukumi Island in exactly $1$ day one way, provided that at least $1$ animal is on board.
・Because of the risk of collision, $2$ or more boats cannot be out at sea at the same time on $1$ day.
・The move ends when all the animals have arrived at New Nsukumi Island.
・It is not necessary to use all the boats. That is, leftover boats may be abandoned on Nsukumi Island.

Find the minimum number of days required to complete the move while keeping the arrangement.
If the move is impossible, output $-1$.

Input

n m

$2 \le n \le 100000$
$2 \le m \le 50$

Output

Find the minimum number of days required to complete the move while keeping the arrangement.
If the move is impossible, output $-1$.
Print a newline at the end.

Sample

Sample 1
Input
3 2
Output
-1

Consider the case of a three-way standoff.

For example, suppose animal $1$ and animal $2$ first try to move by boat.
However, animal $1$ can prey on animal $2$ one-sidedly, so animal $2$ will live in mortal fear on the boat.

For example, suppose only animal $1$ first tries to move by boat.
However, animal $2$, left behind on Nsukumi Island, can prey on animal $3$ one-sidedly, so animal $3$ will live in mortal fear on Nsukumi Island.

The other cases are similar: no matter how hard they try, the move cannot be done.

Sample 2
Input
3 3
Output
1

Consider the case of a three-way standoff.

The boat carries 3 passengers, so by having all 3 board at the same time, they can ride the boat while always maintaining the three-way standoff. Therefore, the move is possible in $1$ day.

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