結果

問題 No.1847 Good Sequence
ユーザー 👑 potato167potato167
提出日時 2021-12-07 11:58:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 879 ms / 3,000 ms
コード長 954 bytes
コンパイル時間 182 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 75,840 KB
最終ジャッジ日時 2024-04-08 21:33:57
合計ジャッジ時間 6,357 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,460 KB
testcase_01 AC 52 ms
62,120 KB
testcase_02 AC 59 ms
64,176 KB
testcase_03 AC 39 ms
53,460 KB
testcase_04 AC 40 ms
53,460 KB
testcase_05 AC 47 ms
59,840 KB
testcase_06 AC 45 ms
59,328 KB
testcase_07 AC 50 ms
61,984 KB
testcase_08 AC 47 ms
59,840 KB
testcase_09 AC 54 ms
59,840 KB
testcase_10 AC 41 ms
53,460 KB
testcase_11 AC 41 ms
53,460 KB
testcase_12 AC 46 ms
59,840 KB
testcase_13 AC 51 ms
62,112 KB
testcase_14 AC 53 ms
64,196 KB
testcase_15 AC 51 ms
62,116 KB
testcase_16 AC 50 ms
62,112 KB
testcase_17 AC 54 ms
64,196 KB
testcase_18 AC 60 ms
66,248 KB
testcase_19 AC 51 ms
62,112 KB
testcase_20 AC 55 ms
62,120 KB
testcase_21 AC 456 ms
75,324 KB
testcase_22 AC 101 ms
68,272 KB
testcase_23 AC 53 ms
62,120 KB
testcase_24 AC 47 ms
59,840 KB
testcase_25 AC 168 ms
70,320 KB
testcase_26 AC 45 ms
59,840 KB
testcase_27 AC 67 ms
70,344 KB
testcase_28 AC 124 ms
68,272 KB
testcase_29 AC 52 ms
62,112 KB
testcase_30 AC 61 ms
68,296 KB
testcase_31 AC 213 ms
72,368 KB
testcase_32 AC 152 ms
70,320 KB
testcase_33 AC 597 ms
75,840 KB
testcase_34 AC 44 ms
59,840 KB
testcase_35 AC 45 ms
59,840 KB
testcase_36 AC 424 ms
75,312 KB
testcase_37 AC 323 ms
75,312 KB
testcase_38 AC 41 ms
53,460 KB
testcase_39 AC 38 ms
53,460 KB
testcase_40 AC 879 ms
75,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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