結果
| 問題 | 
                            No.1233 割り切れない気持ち
                             | 
                    
| コンテスト | |
| ユーザー | 
                             uni_python
                         | 
                    
| 提出日時 | 2020-09-20 15:53:40 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                TLE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 951 bytes | 
| コンパイル時間 | 225 ms | 
| コンパイル使用メモリ | 82,304 KB | 
| 実行使用メモリ | 108,544 KB | 
| 最終ジャッジ日時 | 2024-06-24 10:46:50 | 
| 合計ジャッジ時間 | 24,204 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 25 TLE * 1 -- * 13 | 
ソースコード
import sys
input=sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
"""
A[i]=aを見る時
aより小さい数は全部そのまま足す,
aより大きく,2aより小さいものは全部足して,個数*aを引く
"""
def main():
    import bisect
    
    mod=10**9+7
    N=I()
    A=LI()
    A.sort()
    M=A[-1]
    S=[0]*(N+1)
    
    for i in range(N):
        S[i+1]=S[i]+A[i]
        
    def calc(a):
        if a==1:
            return 0
        
        res=0
        now=a
        while now<=M+a:
            num1=bisect.bisect_left(A,now-a)
            num2=bisect.bisect_left(A,now)
            temp=S[num2] - S[num1]
            temp-=(num2-num1)*(now-a)
            res+=temp
            
            now+=a
        return res
    
    ans=0
    for a in A:
        ans+=calc(a)
        
    print(ans)
            
            
main()
            
            
            
        
            
uni_python