結果
問題 |
No.14 最小公倍数ソート
|
ユーザー |
|
提出日時 | 2021-04-14 09:11:59 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,088 bytes |
コンパイル時間 | 168 ms |
コンパイル使用メモリ | 82,372 KB |
実行使用メモリ | 80,964 KB |
最終ジャッジ日時 | 2024-06-30 10:01:56 |
合計ジャッジ時間 | 3,891 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 3 WA * 17 |
ソースコード
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): 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) for c in cand[now]: 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)