結果

問題 No.2956 Substitute with Average
ユーザー hirayuu_yc
提出日時 2024-11-08 22:31:34
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 413 bytes
コンパイル時間 335 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 324,868 KB
最終ジャッジ日時 2024-11-08 22:32:05
合計ジャッジ時間 25,798 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 3
other AC * 1 WA * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import Counter
N=int(input())
A=list(map(int,input().split()))
ans=N*(N+1)//2
for i in range(1,30):
	cum=[0]*(N+1)
	for j in range(N):
		cum[j+1]=cum[j]+(A[j]-i)
	left=Counter()
	dl=Counter()
	cnt2=Counter({0:1})
	for j in range(N):
		if A[j]!=i:
			left[cum[j]]+=1
		if A[j]!=i:
			dl[cum[j+1]]+=left[cum[j+1]]
		cnt2[cum[j+1]]+=1
	for c in cnt2:
		ans-=(cnt2[c]*(cnt2[c]-1)//2-dl[c])
print(ans)
0