結果

問題 No.2956 Substitute with Average
ユーザー hato336
提出日時 2024-11-08 22:18:33
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 503 bytes
コンパイル時間 393 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 363,292 KB
最終ジャッジ日時 2024-11-08 22:18:56
合計ジャッジ時間 20,007 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 8 WA * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

import itertools
n = int(input())
a = list(map(int,input().split()))
b = [[0 for j in range(n)] for i in range(31)]
for i in range(31):
    for j in range(n):
        b[i][j] = a[j] - i
    b[i] = list(itertools.accumulate(b[i])) + [0]
ans = 0
import collections
c = [collections.defaultdict(int) for i in range(31)]
for i in reversed(range(n)):
    for j in range(31):
        c[j][b[j][i]] += 1
    ans -= c[a[i]][b[a[i]][i]]
    #print(i,c[a[i]][b[a[i]][i]])
    

    
ans += n*(n+1)//2
print(ans+1)
0