結果

問題 No.1917 LCMST
ユーザー とりゐとりゐ
提出日時 2022-04-28 18:10:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,201 ms / 4,000 ms
コード長 1,193 bytes
コンパイル時間 778 ms
コンパイル使用メモリ 87,256 KB
実行使用メモリ 312,344 KB
最終ジャッジ日時 2023-09-10 16:53:15
合計ジャッジ時間 31,858 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
79,932 KB
testcase_01 AC 112 ms
79,704 KB
testcase_02 AC 112 ms
79,852 KB
testcase_03 AC 142 ms
80,228 KB
testcase_04 AC 140 ms
80,372 KB
testcase_05 AC 140 ms
80,328 KB
testcase_06 AC 142 ms
80,420 KB
testcase_07 AC 141 ms
80,364 KB
testcase_08 AC 114 ms
79,812 KB
testcase_09 AC 1,155 ms
282,064 KB
testcase_10 AC 1,156 ms
280,564 KB
testcase_11 AC 1,201 ms
312,344 KB
testcase_12 AC 1,128 ms
294,512 KB
testcase_13 AC 686 ms
254,124 KB
testcase_14 AC 1,145 ms
293,780 KB
testcase_15 AC 535 ms
250,544 KB
testcase_16 AC 681 ms
250,304 KB
testcase_17 AC 876 ms
280,164 KB
testcase_18 AC 925 ms
273,628 KB
testcase_19 AC 543 ms
253,896 KB
testcase_20 AC 477 ms
251,064 KB
testcase_21 AC 565 ms
253,340 KB
testcase_22 AC 476 ms
250,736 KB
testcase_23 AC 472 ms
250,812 KB
testcase_24 AC 560 ms
253,800 KB
testcase_25 AC 473 ms
250,548 KB
testcase_26 AC 506 ms
250,456 KB
testcase_27 AC 533 ms
253,504 KB
testcase_28 AC 545 ms
253,548 KB
testcase_29 AC 904 ms
254,880 KB
testcase_30 AC 879 ms
254,688 KB
testcase_31 AC 910 ms
254,924 KB
testcase_32 AC 920 ms
254,780 KB
testcase_33 AC 927 ms
254,892 KB
testcase_34 AC 296 ms
217,940 KB
testcase_35 AC 298 ms
218,368 KB
testcase_36 AC 291 ms
218,296 KB
testcase_37 AC 880 ms
255,208 KB
testcase_38 AC 962 ms
254,716 KB
testcase_39 AC 909 ms
254,692 KB
testcase_40 AC 948 ms
254,960 KB
testcase_41 AC 933 ms
254,892 KB
testcase_42 AC 997 ms
254,712 KB
testcase_43 AC 323 ms
223,860 KB
testcase_44 AC 331 ms
224,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#UnionFind
from collections import defaultdict

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def same(self, x, y):
        return self.find(x) == self.find(y)

from collections import defaultdict
n=int(input())
a=list(map(int,input().split()))
m=10**5
c=[0]*(m+1)
ans=0

for i in a:
  if c[i]==0:
    c[i]=1
  else:
    ans+=i

s=set()
edge=defaultdict(list)
d=[-1]*(m+1)

for i in range(1,m+1):
  for j in range(i,m+1,i):
    if c[j]:
      if d[i]==-1:
        d[i]=j
      else:
        w=d[i]*j//i
        s.add(w)
        edge[w].append((d[i],j))

s=sorted(list(s))
uf=UnionFind(m+1)

for w in s:
  for u,v in edge[w]:
    if not uf.same(u,v):
      uf.union(u,v)
      ans+=w

print(ans)
0