結果

問題 No.1049 Zero (Exhaust)
ユーザー FromBooskaFromBooska
提出日時 2023-02-17 11:51:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 218 ms / 2,000 ms
コード長 699 bytes
コンパイル時間 318 ms
コンパイル使用メモリ 86,908 KB
実行使用メモリ 148,144 KB
最終ジャッジ日時 2023-09-26 12:25:32
合計ジャッジ時間 5,618 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,484 KB
testcase_01 AC 74 ms
71,340 KB
testcase_02 AC 72 ms
71,432 KB
testcase_03 AC 177 ms
122,536 KB
testcase_04 AC 70 ms
71,604 KB
testcase_05 AC 164 ms
121,372 KB
testcase_06 AC 217 ms
148,144 KB
testcase_07 AC 85 ms
77,456 KB
testcase_08 AC 118 ms
95,160 KB
testcase_09 AC 172 ms
122,816 KB
testcase_10 AC 210 ms
146,656 KB
testcase_11 AC 210 ms
146,964 KB
testcase_12 AC 218 ms
147,852 KB
testcase_13 AC 116 ms
94,492 KB
testcase_14 AC 121 ms
96,228 KB
testcase_15 AC 171 ms
122,432 KB
testcase_16 AC 164 ms
121,552 KB
testcase_17 AC 163 ms
121,492 KB
testcase_18 AC 211 ms
146,984 KB
testcase_19 AC 168 ms
122,488 KB
testcase_20 AC 116 ms
94,908 KB
testcase_21 AC 169 ms
122,860 KB
testcase_22 AC 123 ms
95,972 KB
testcase_23 AC 217 ms
148,116 KB
testcase_24 AC 215 ms
148,140 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# あるステップの段階でN=0 or N!=0
# N=0なら、掛け算でP通り、足し算で1通り、の合計P+1通りで、次もN=0となる
# N!=0なら、掛け算で1通り(0、素数なので)、足し算で1通りの合計2通りで次が0になる
# 操作は全部でP*2通りなので、残りはN!=0となる

P, K = map(int, input().split())
mod = 10**9+7

# dp[操作番号][0 for 0, 1 for nonzero]
dp = [[0]*2 for i in range(K+1)]
dp[0][0] = 1

for i in range(1, K+1):
    dp[i][0] += dp[i-1][0]*(P+1)
    dp[i][0] += dp[i-1][1]*(2)
    dp[i][0] %= mod
    dp[i][1] += dp[i-1][0]*(P-1)
    dp[i][1] += dp[i-1][1]*(P*2-2)
    dp[i][1] %= mod

#print(dp)

ans = dp[K][0]%mod
print(ans)
0