結果
| 問題 |
No.2956 Substitute with Average
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-11-08 22:08:30 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 770 ms / 3,000 ms |
| コード長 | 468 bytes |
| コンパイル時間 | 291 ms |
| コンパイル使用メモリ | 82,432 KB |
| 実行使用メモリ | 242,444 KB |
| 最終ジャッジ日時 | 2024-11-08 22:08:49 |
| 合計ジャッジ時間 | 13,938 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 |
ソースコード
n = int(input())
A = list(map(int, input().split()))
ans = n * (n + 1) // 2
for t in range(1, 31):
B = [a - t for a in A]
cnt = {}
tot = 0
cnt[0] = 1
for b in B:
tot += b
ans -= cnt.get(tot, 0)
cnt[tot] = cnt.get(tot, 0) + 1
cnt = {}
tot = 0
for b in B:
if b != 0:
cnt[tot] = cnt.get(tot, 0) + 1
tot += b
if b != 0:
ans += cnt.get(tot, 0)
ans += 1
print(ans)