結果

問題 No.1049 Zero (Exhaust)
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2021-06-15 15:03:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 136 ms / 2,000 ms
コード長 743 bytes
コンパイル時間 628 ms
コンパイル使用メモリ 87,224 KB
実行使用メモリ 75,628 KB
最終ジャッジ日時 2023-08-27 06:01:37
合計ジャッジ時間 4,422 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,488 KB
testcase_01 AC 72 ms
71,076 KB
testcase_02 AC 71 ms
71,072 KB
testcase_03 AC 119 ms
75,356 KB
testcase_04 AC 73 ms
71,432 KB
testcase_05 AC 108 ms
75,324 KB
testcase_06 AC 136 ms
75,508 KB
testcase_07 AC 83 ms
75,512 KB
testcase_08 AC 94 ms
75,320 KB
testcase_09 AC 119 ms
75,232 KB
testcase_10 AC 123 ms
75,364 KB
testcase_11 AC 125 ms
75,440 KB
testcase_12 AC 132 ms
75,532 KB
testcase_13 AC 90 ms
75,500 KB
testcase_14 AC 102 ms
75,396 KB
testcase_15 AC 119 ms
75,400 KB
testcase_16 AC 111 ms
75,448 KB
testcase_17 AC 111 ms
75,628 KB
testcase_18 AC 125 ms
75,280 KB
testcase_19 AC 119 ms
75,564 KB
testcase_20 AC 96 ms
75,356 KB
testcase_21 AC 120 ms
75,480 KB
testcase_22 AC 103 ms
75,504 KB
testcase_23 AC 135 ms
75,288 KB
testcase_24 AC 136 ms
75,564 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def main0(p,k):
	# 自明DP
	mod=10**9+7
	dp=[0]*p
	dp[0]=1
	for _ in range(k):
		ndp=[0]*p
		for j in range(p):
			# dp[j]からの遷移
			if dp[j]==0:continue
			for i in range(p):
				# (1)
				ndp[(j+i)%p]+=dp[j]
				ndp[(j+i)%p]%=mod
				# (2)
				ndp[(j*i)%p]+=dp[j]
				ndp[(j*i)%p]%=mod
		dp=ndp
	return dp[0]

def main1(p,k):
	mod=10**9+7
	# dp[i]:N=iとなる操作列の個数
	# 初期値dp[0]=0

	dp0=1 # dp[0]の値
	dp1=0 # sum(dp)-dp[0]
	for _ in range(k):
		ndp0=dp1+dp0 # (1)
		ndp0+=dp0*p%mod+dp1 # (2)
		ndp1=(dp0+dp1)*(p-1)%mod # (1)
		ndp1+=dp1*(p-1) # (2)
		dp0=ndp0%mod
		dp1=ndp1%mod

	return dp0

if __name__=='__main__':
	p,k=map(int,input().split())
	#ret0=main0(p,k)
	#print(ret0)
	ret1=main1(p,k)
	print(ret1)
	
0