結果

問題 No.740 幻の木
ユーザー はむ吉🐹はむ吉🐹
提出日時 2018-10-05 21:34:39
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 17 ms / 2,000 ms
コード長 558 bytes
コンパイル時間 156 ms
コンパイル使用メモリ 10,676 KB
実行使用メモリ 7,948 KB
最終ジャッジ日時 2023-08-02 16:56:53
合計ジャッジ時間 967 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
7,784 KB
testcase_01 AC 16 ms
7,896 KB
testcase_02 AC 16 ms
7,780 KB
testcase_03 AC 15 ms
7,772 KB
testcase_04 AC 16 ms
7,756 KB
testcase_05 AC 15 ms
7,948 KB
testcase_06 AC 15 ms
7,824 KB
testcase_07 AC 15 ms
7,820 KB
testcase_08 AC 15 ms
7,896 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3

T = 12


def solve(n, m, p, q):
    per_cycle = (T - q) * m + q * 2 * m
    num_cycles, rest_leaves = divmod(n, per_cycle)
    per_months = [m] * (p - 1) + [2 * m] * q + [m] * (T - p - q + 1)
    for idx_month, per_month in enumerate(per_months):
        if rest_leaves <= 0:
            return num_cycles * T + idx_month
        else:
            rest_leaves -= per_month
    raise Exception("Error")


def main():
    n, m, p, q = (int(z) for z in input().split())
    print(solve(n, m, p, q))

if __name__ == '__main__':
    main()
0