結果

問題 No.1233 割り切れない気持ち
ユーザー ygd.ygd.
提出日時 2020-09-18 22:55:33
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 708 ms / 3,153 ms
コード長 989 bytes
コンパイル時間 710 ms
コンパイル使用メモリ 87,312 KB
実行使用メモリ 108,808 KB
最終ジャッジ日時 2023-09-04 21:51:46
合計ジャッジ時間 12,595 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
72,368 KB
testcase_01 AC 72 ms
72,344 KB
testcase_02 AC 80 ms
76,912 KB
testcase_03 AC 91 ms
77,660 KB
testcase_04 AC 90 ms
77,312 KB
testcase_05 AC 78 ms
76,804 KB
testcase_06 AC 78 ms
77,332 KB
testcase_07 AC 229 ms
84,984 KB
testcase_08 AC 282 ms
90,116 KB
testcase_09 AC 475 ms
101,776 KB
testcase_10 AC 502 ms
104,976 KB
testcase_11 AC 200 ms
84,392 KB
testcase_12 AC 511 ms
108,528 KB
testcase_13 AC 523 ms
108,776 KB
testcase_14 AC 538 ms
108,340 KB
testcase_15 AC 562 ms
108,660 KB
testcase_16 AC 568 ms
108,616 KB
testcase_17 AC 142 ms
106,224 KB
testcase_18 AC 708 ms
108,808 KB
testcase_19 AC 146 ms
108,732 KB
testcase_20 AC 144 ms
106,420 KB
testcase_21 AC 170 ms
107,336 KB
testcase_22 AC 169 ms
107,156 KB
testcase_23 AC 171 ms
107,308 KB
testcase_24 AC 170 ms
107,340 KB
testcase_25 AC 168 ms
107,340 KB
testcase_26 AC 168 ms
107,308 KB
testcase_27 AC 185 ms
108,016 KB
testcase_28 AC 183 ms
108,180 KB
testcase_29 AC 184 ms
107,736 KB
testcase_30 AC 182 ms
108,184 KB
testcase_31 AC 179 ms
107,904 KB
testcase_32 AC 180 ms
108,176 KB
testcase_33 AC 180 ms
108,212 KB
testcase_34 AC 179 ms
107,920 KB
testcase_35 AC 181 ms
108,068 KB
testcase_36 AC 180 ms
107,960 KB
testcase_37 AC 75 ms
72,540 KB
testcase_38 AC 144 ms
106,144 KB
testcase_39 AC 440 ms
107,532 KB
testcase_40 AC 433 ms
107,476 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class BIT:
    def __init__(self, n):
        self.n = n
        self.data = [0]*(n+1)
 
    def to_sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= (i & -i)
        return s
 
    def add(self, i, x):
        while i <= self.n:
            self.data[i] += x
            i += (i & -i)
 
    def get(self, i, j):
        return self.to_sum(j)-self.to_sum(i-1)


N = int(input())
MAX = 2*pow(10,5)+10
Tree = BIT(MAX)
A = list(map(int,input().split()))
for i in range(N):
  Tree.add(A[i],1)
S = sum(A)
MAX = max(A)
A.sort()
ans = 0
prevx = -1
for x in A:
  if x == 1:
    continue
  if x == prevx:
    ans += temp
    continue
  wari = 0; now = x; fac = 1
  for i in range(200000):
    if now+x-1 >= MAX:
      wari += Tree.get(now,MAX)*fac
      break
    else:
      wari += Tree.get(now,now+x-1)*fac
    now += x
    fac += 1
    if now > MAX + x:
      break
  #print(wari,S-wari*x)
  temp = S - wari*x
  ans += temp
  prevx = x
print(ans)

0