結果

問題 No.1847 Good Sequence
ユーザー 👑 potato167potato167
提出日時 2021-12-07 11:52:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,010 ms / 3,000 ms
コード長 1,013 bytes
コンパイル時間 174 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 76,008 KB
最終ジャッジ日時 2024-04-08 21:34:49
合計ジャッジ時間 6,732 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,460 KB
testcase_01 AC 49 ms
64,196 KB
testcase_02 AC 59 ms
64,196 KB
testcase_03 AC 38 ms
53,460 KB
testcase_04 AC 38 ms
53,460 KB
testcase_05 AC 43 ms
59,848 KB
testcase_06 AC 42 ms
59,336 KB
testcase_07 AC 45 ms
62,112 KB
testcase_08 AC 43 ms
59,848 KB
testcase_09 AC 48 ms
61,996 KB
testcase_10 AC 38 ms
53,460 KB
testcase_11 AC 38 ms
53,460 KB
testcase_12 AC 43 ms
59,848 KB
testcase_13 AC 46 ms
62,116 KB
testcase_14 AC 52 ms
64,220 KB
testcase_15 AC 49 ms
64,220 KB
testcase_16 AC 50 ms
62,112 KB
testcase_17 AC 54 ms
64,220 KB
testcase_18 AC 59 ms
66,280 KB
testcase_19 AC 50 ms
62,108 KB
testcase_20 AC 53 ms
64,196 KB
testcase_21 AC 520 ms
75,524 KB
testcase_22 AC 114 ms
70,376 KB
testcase_23 AC 50 ms
64,196 KB
testcase_24 AC 45 ms
59,848 KB
testcase_25 AC 191 ms
75,392 KB
testcase_26 AC 44 ms
59,848 KB
testcase_27 AC 76 ms
72,464 KB
testcase_28 AC 142 ms
72,428 KB
testcase_29 AC 51 ms
64,196 KB
testcase_30 AC 69 ms
70,400 KB
testcase_31 AC 248 ms
75,392 KB
testcase_32 AC 172 ms
73,064 KB
testcase_33 AC 685 ms
76,008 KB
testcase_34 AC 46 ms
61,980 KB
testcase_35 AC 45 ms
59,848 KB
testcase_36 AC 490 ms
75,392 KB
testcase_37 AC 373 ms
75,392 KB
testcase_38 AC 38 ms
53,460 KB
testcase_39 AC 40 ms
53,460 KB
testcase_40 AC 1,010 ms
75,516 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def mul(p,q,mod):
	n=len(p)
	ans=[[0 for i in range(n)] for j in range(n)]
	for i in range(n):
		for j in range(n):
			for k in range(n):
				ans[i][k]+=(p[i][j]*q[j][k])%mod
				if ans[i][k]>=mod:
					ans[i][k]-=mod
	return ans
def my_pow(p,x,mod):
	n=len(p)
	ans=[[0 for i in range(n)]for j in range(n)]
	for i in range(n):
		ans[i][i]=1
	while x>0:
		if x%2==1:
			ans=mul(ans,p,mod)
		x//=2
		p=mul(p,p,mod)
	return ans
MOD=10**9+7
L,N,M=map(int,input().split())
K=list(map(int,input().split()))
s=set()
tmp=0
D=sum(K)+M+1
base=[[0 for i in range(D)]for j in range(D)]
for i in range(M):
	for j in range(D):
		if j<tmp or tmp+K[i]+1<=j:
			base[j][tmp]=1
	for j in range(K[i]):
		base[j+tmp][j+1+tmp]=1
	tmp+=K[i]+1
	base[tmp-1][tmp-1]=1
	s.add(tmp-2)
for i in range(D):
	base[i][D-1]=N-M
tmp=0
for i in range(M):
	tmp+=K[i]-1
	for j in range(D):
		if j!=tmp+1:
			base[tmp][j]=0
	tmp+=2
base=my_pow(base,L,MOD)
ans=pow(N,L,MOD)
for i in range(D):
	if i not in s:
		ans-=base[D-1][i]
print((ans%MOD+MOD)%MOD)
0