結果

問題 No.2846 Birthday Cake
ユーザー 👑 rin204rin204
提出日時 2024-08-23 22:03:48
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,089 bytes
コンパイル時間 217 ms
コンパイル使用メモリ 82,264 KB
実行使用メモリ 363,344 KB
最終ジャッジ日時 2024-08-23 22:03:59
合計ジャッジ時間 10,187 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
53,792 KB
testcase_01 AC 45 ms
65,556 KB
testcase_02 AC 574 ms
360,764 KB
testcase_03 AC 34 ms
53,484 KB
testcase_04 AC 42 ms
53,132 KB
testcase_05 AC 607 ms
362,636 KB
testcase_06 WA -
testcase_07 AC 580 ms
363,344 KB
testcase_08 WA -
testcase_09 AC 417 ms
360,692 KB
testcase_10 AC 338 ms
360,328 KB
testcase_11 AC 300 ms
360,680 KB
testcase_12 AC 469 ms
339,236 KB
testcase_13 AC 452 ms
340,432 KB
testcase_14 AC 34 ms
53,260 KB
testcase_15 AC 34 ms
53,356 KB
testcase_16 AC 34 ms
53,384 KB
testcase_17 AC 35 ms
52,988 KB
testcase_18 AC 39 ms
52,772 KB
testcase_19 AC 36 ms
53,948 KB
testcase_20 AC 346 ms
280,348 KB
testcase_21 AC 36 ms
52,924 KB
testcase_22 AC 454 ms
247,348 KB
testcase_23 AC 507 ms
342,672 KB
testcase_24 AC 321 ms
338,828 KB
testcase_25 AC 36 ms
52,920 KB
testcase_26 AC 152 ms
135,288 KB
testcase_27 AC 177 ms
209,756 KB
testcase_28 AC 40 ms
53,128 KB
testcase_29 AC 34 ms
52,460 KB
testcase_30 AC 35 ms
53,544 KB
testcase_31 AC 361 ms
245,100 KB
testcase_32 AC 289 ms
298,132 KB
testcase_33 AC 296 ms
338,952 KB
testcase_34 AC 249 ms
259,752 KB
testcase_35 WA -
testcase_36 AC 445 ms
319,128 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import lcm

k, n = map(int, input().split())
if n == k or k == 1:
    print(1)
    exit()
nCk = [[0] * (n + 1) for _ in range(n + 1)]
nCk[0][0] = 1
for i in range(1, n + 1):
    nCk[i][0] = 1
    for j in range(1, n + 1):
        nCk[i][j] = nCk[i - 1][j - 1] + nCk[i - 1][j]

ng = [False] * 25
ng[13] = True
ng[17] = True
ng[19] = True
ng[23] = True

lc = 1
for i in range(1, n + 1):
    if ng[i]:
        continue
    lc = lcm(lc, i)

dp = [[-1] * (lc + 1) for _ in range((n + 1) * (n + 1) + n + 1)]


def dfs(t, x, tot):
    if tot == lc:
        global ans
        if x == 0:
            return 1
        return 0
    if t == 0:
        return 0

    if ng[t]:
        return dfs(t - 1, x, tot)

    if tot + (lc // t) * x > lc:
        return 0

    if dp[t * (n + 1) + x][tot] != -1:
        return dp[t * (n + 1) + x][tot]

    ret = 0
    for j in range(x + 1):
        ntot = tot + (lc // t) * j
        if ntot > lc:
            break
        ret += dfs(t - 1, x - j, ntot) * nCk[x][j]

    dp[t * (n + 1) + x][tot] = ret
    return ret


ans = dfs(n, k, 0)
print(ans)
0