結果

問題 No.1233 割り切れない気持ち
ユーザー None
提出日時 2021-03-16 01:53:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 207 ms / 3,153 ms
コード長 648 bytes
コンパイル時間 353 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 128,256 KB
最終ジャッジ日時 2024-11-07 14:04:39
合計ジャッジ時間 7,418 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

diff #

def deg(A):
    """
    連続して続く文字を圧縮する(※Counterではない)
    [1,1,1,2,2,2,3] -> [(1,3),(2,3),(3,1)]
    """
    res=[]
    a0, cnt=A[0], 1
    for a in A[1:]+[None]:
        if a!=a0: res.append((a0,cnt)); cnt=1
        else: cnt+=1
        a0=a
    return res

import sys
input = sys.stdin.readline

N=int(input())
A=list(map(int, input().split()))
A.sort()
M=max(A)
S=[0]*(M+1)
for a in A:
    S[a]+=1
C=[0]
for a in S:
    C.append(C[-1]+a)

res=N*sum(A)
for a,cnt in deg(A):
    l,r=0,a-1
    k=0
    while l+a<=M:
        l+=a
        r+=a
        k+=1
        res-=(C[min(r+1,M+1)]-C[l])*k*a*cnt

print(res)
0