結果

問題 No.2956 Substitute with Average
コンテスト
ユーザー hirayuu_yc
提出日時 2024-11-08 22:31:34
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
WA  
実行時間 -
コード長 413 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 234 ms
コンパイル使用メモリ 85,040 KB
実行使用メモリ 311,580 KB
最終ジャッジ日時 2026-05-09 02:27:43
合計ジャッジ時間 19,075 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 3
other AC * 1 WA * 24
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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