結果

問題 No.1848 Long Prefixes
ユーザー 👑 potato167potato167
提出日時 2021-12-07 14:50:26
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 758 bytes
コンパイル時間 500 ms
コンパイル使用メモリ 87,072 KB
実行使用メモリ 125,976 KB
最終ジャッジ日時 2023-09-11 18:02:33
合計ジャッジ時間 6,881 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 71 ms
71,332 KB
testcase_21 AC 70 ms
71,152 KB
testcase_22 AC 70 ms
71,280 KB
testcase_23 AC 69 ms
71,160 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 70 ms
71,224 KB
testcase_27 AC 68 ms
71,060 KB
testcase_28 AC 69 ms
71,336 KB
testcase_29 AC 71 ms
71,020 KB
testcase_30 AC 76 ms
71,204 KB
testcase_31 AC 69 ms
71,212 KB
testcase_32 AC 73 ms
71,268 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

def z_algo(p):
	n=len(p)
	Z=[0]*n
	Z[0]=n
	i=1
	j=0
	while i<n:
		while i+j<n and p[i]==p[i+j]:
			j+=1
		Z[i]=j
		if j==0:
			i+=1
			continue
		k=1
		while k<j and k+Z[k]<j:
			Z[i+k]=Z[k]
			k+=1
		i+=k
		j-=k
	return Z

N=int(input())
A=list(map(int,input().split()))
S=input()
M=10**9+7
half=(M+1)//2
p=[('#',100)]*(N)
cum_sum=[0]*(N+1)
for i in range(N-1):
	p[i]=(S[i+1],A[i+1])
	cum_sum[i+1]=(cum_sum[i]+A[i+1])%M
cum_sum[N]=cum_sum[N-1]
Z=z_algo(p)
ans=0
for i in range(N):
	if S[i]!=S[0]:
		continue
	if A[i]<A[0]:
		ans+=((A[i]+1)*A[i])//2
		ans%=M 
	else:
		ans+=(A[0]*(A[i]-A[0]))
		ans%=M
		ans+=(A[0]*(A[0]+1))//2
		ans%=M
		ans+=cum_sum[Z[i]]
		if i+Z[i]+1<N and S[i+1+Z[i]]==S[1+Z[i]]:
			ans+=min(A[i+1+Z[i]],A[1+Z[i]])
		ans%=M
print(ans)

0