結果

問題 No.634 硬貨の枚数1
ユーザー Yukino DX.
提出日時 2023-11-17 16:23:16
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
実行時間 -
コード長 471 bytes
コンパイル時間 531 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 16,256 KB
最終ジャッジ日時 2024-09-26 05:25:23
合計ジャッジ時間 5,113 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12 TLE * 1 -- * 62
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from itertools import takewhile, count

sys.setrecursionlimit(10**7)

n = int(input())
koukas = [
    k * (k + 1) // 2 for k in takewhile(lambda k: k * (k + 1) // 2 <= n, count(1))
]


def can(m, n):
    if m == 0 or n == 0:
        return m == n

    for kouka in koukas:
        if kouka > n:
            break
        if can(m - 1, n - kouka):
            return True

    return False


for m in count(1):
    if can(m, n):
        print(m)
        exit()
0