結果

問題 No.2396 等差二項展開
ユーザー rlangevinrlangevin
提出日時 2023-07-28 23:06:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,122 ms / 6,000 ms
コード長 856 bytes
コンパイル時間 289 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 76,544 KB
最終ジャッジ日時 2024-04-16 07:03:11
合計ジャッジ時間 11,333 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
51,712 KB
testcase_01 AC 41 ms
51,968 KB
testcase_02 AC 41 ms
51,968 KB
testcase_03 AC 40 ms
52,224 KB
testcase_04 AC 41 ms
51,968 KB
testcase_05 AC 41 ms
51,968 KB
testcase_06 AC 40 ms
52,480 KB
testcase_07 AC 40 ms
52,224 KB
testcase_08 AC 41 ms
52,096 KB
testcase_09 AC 43 ms
51,968 KB
testcase_10 AC 41 ms
51,584 KB
testcase_11 AC 41 ms
51,968 KB
testcase_12 AC 41 ms
51,840 KB
testcase_13 AC 51 ms
59,776 KB
testcase_14 AC 52 ms
61,184 KB
testcase_15 AC 59 ms
62,464 KB
testcase_16 AC 200 ms
72,192 KB
testcase_17 AC 551 ms
76,032 KB
testcase_18 AC 849 ms
76,160 KB
testcase_19 AC 1,122 ms
76,544 KB
testcase_20 AC 42 ms
52,096 KB
testcase_21 AC 42 ms
52,608 KB
testcase_22 AC 42 ms
52,480 KB
testcase_23 AC 720 ms
75,904 KB
testcase_24 AC 897 ms
76,288 KB
testcase_25 AC 891 ms
76,032 KB
testcase_26 AC 827 ms
76,032 KB
testcase_27 AC 892 ms
76,032 KB
testcase_28 AC 747 ms
76,032 KB
testcase_29 AC 893 ms
76,288 KB
testcase_30 AC 809 ms
76,032 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, M, L, K, B = map(int, input().split())
if L == 1:
    print(pow(1 + M, N, B))
    exit()

now = [0] * L
now[0] = now[1] = 1
lst = []
while N != 1:
    if N % 2 == 0:
        lst.append(1)
        N //= 2
    else:
        lst.append(0)
        N -= 1
lst.reverse()
for flag in lst:
    if flag:
        nex = [0] * (2 * L)
        for i in range(L):
            for j in range(L):
                nex[i + j] += now[i] * now[j]
                nex[i + j] %= B
        for i in range(L, 2 * L):
            nex[i - L] += nex[i] * M
            nex[i - L - 1] %= B
    else:
        nex = [0] * (L + 1)
        for i in range(L):
            nex[i] += now[i]
            nex[i + 1] += now[i]
            nex[i] %= B
            nex[i + 1] %= B
        nex[0] += nex[L] * M
        nex[0] %= B                         
    now = nex[:L]

    
print(now[K])
0