結果
問題 | No.2956 Substitute with Average |
ユーザー |
|
提出日時 | 2024-11-08 22:37:40 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 915 ms / 3,000 ms |
コード長 | 383 bytes |
コンパイル時間 | 824 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 264,124 KB |
最終ジャッジ日時 | 2024-11-08 22:38:01 |
合計ジャッジ時間 | 18,440 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 25 |
ソースコード
from collections import CounterN=int(input())A=list(map(int,input().split()))ans=N*(N+1)//2for i in range(1,31):cum=[0]*(N+1)for j in range(N):cum[j+1]=cum[j]+(A[j]-i)cnt=Counter({0:1})cnt2=Counter({0:1})for j in range(N):if cum[j]!=cum[j+1]:cnt[cum[j+1]]+=1cnt2[cum[j+1]]+=1for c in cnt:ans-=(cnt2[c]*(cnt2[c]-1)//2-cnt[c]*(cnt[c]-1)//2)print(1+ans)