問題一覧 > 通常問題

No.740 The Phantom Tree

レベル : / AI推定難易度 : 140 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 294
作問者 : gotutiyan / テスター : ciel
お気に入りにしたユーザー ProblemId : 2007 / 自分の提出
問題文最終更新日: 2018-10-05 21:38:09
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 201 (順位表) の他の問題:

Problem Statement

In a certain village, there is a tree that the villagers call the Phantom Tree. When fully grown, this tree bears N leaves, but after that it sheds M leaves every month, and once it has eventually shed all of its leaves, it will never bear leaves again.
Furthermore, this village has a "windy period" lasting Q months, starting from month P every year, and during this period the Phantom Tree sheds 2×M leaves.

In this village, it is now January, and the Phantom Tree has just become fully grown. Output in which month, counting from the start, it sheds all of its leaves.

Input

N M P Q

N is the number of leaves on the Phantom Tree when it is fully grown.
M is the number of leaves shed each month.
The windy period lasts Q months starting from month P every year.
1<=N<=1000000(=10^6)
1<=M<=N
1<=P<=12
1<=Q<=13-P (the windy period never continues across a year boundary)

Output

Output in which month, counting from the start, the Phantom Tree sheds all of its leaves. Print a newline at the end.

Sample

Sample 1
Input
10 1 1 3
Output
7

During the 3 months of January, February, and March, the wind is strong, so the tree sheds 2 leaves each month. The remaining 4 leaves are shed one at a time over 4 months. Therefore, all the leaves have fallen in the 7th month.

Sample 2
Input
50 10 4 4
Output
4

In January, February, and March, the tree sheds 10 leaves each month. April, May, June, and July are windy, so the remaining 20 leaves are all shed by April. Therefore, all the leaves have fallen in the 4th month.

Sample 3
Input
100 2 5 8
Output
31

The windy period is the 8 months from May to December every year.

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