結果

問題 No.14 最小公倍数ソート
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2021-04-14 09:17:15
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,054 bytes
コンパイル時間 332 ms
コンパイル使用メモリ 87,132 KB
実行使用メモリ 82,168 KB
最終ジャッジ日時 2023-09-12 22:36:50
合計ジャッジ時間 4,938 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
76,296 KB
testcase_01 AC 80 ms
76,228 KB
testcase_02 AC 82 ms
76,236 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappop, heappush, heapify
n = int(input())
A = list(map(int,input().split()))

count = [0]*(10**4+5)
h = []
for a in A[1:]:
    count[a] += 1
    heappush(h, a)
now = A[0]
ans = [now]

cand = [[] for i in range(10**4+5)]
for i in range(10**4+1):
    if count[i] or now==i:
        for j in range(i,10**4+2,i):
            if count[j]:
                cand[i].append(j)
        cand[i] = cand[i][::-1]

for i in range(n-1):
    cand2 = []
    for j in range(1,int(now**0.5)+1):
        if now%j == 0:
            if count[j]:
                cand2.append(j)
            if count[now//j]:
                cand2.append(now//j)
    if cand2 == []:
        while count[h[0]] == 0:
            heappop(h)
        while cand[now] and count[cand[now][-1]] == 0:
            cand[now].pop()
        if cand[now] == [] or h[0]*now <= cand[now][-1]:
            nex = heappop(h)
        else:
            nex = cand[now].pop()
    else:
        cand2.sort()
        nex = cand2[0]
    count[nex] -= 1
    ans.append(nex)
    now = nex
print(*ans)
0