結果
問題 | No.14 最小公倍数ソート |
ユーザー | 👑 cologne |
提出日時 | 2022-01-21 12:59:09 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 146 ms / 5,000 ms |
コード長 | 1,286 bytes |
コンパイル時間 | 180 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 78,440 KB |
最終ジャッジ日時 | 2024-05-04 01:42:32 |
合計ジャッジ時間 | 3,199 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
58,228 KB |
testcase_01 | AC | 35 ms
57,344 KB |
testcase_02 | AC | 41 ms
58,112 KB |
testcase_03 | AC | 74 ms
76,496 KB |
testcase_04 | AC | 128 ms
77,524 KB |
testcase_05 | AC | 114 ms
77,596 KB |
testcase_06 | AC | 116 ms
78,440 KB |
testcase_07 | AC | 126 ms
77,840 KB |
testcase_08 | AC | 128 ms
78,204 KB |
testcase_09 | AC | 130 ms
78,300 KB |
testcase_10 | AC | 136 ms
77,696 KB |
testcase_11 | AC | 130 ms
78,248 KB |
testcase_12 | AC | 133 ms
77,980 KB |
testcase_13 | AC | 146 ms
77,908 KB |
testcase_14 | AC | 137 ms
77,812 KB |
testcase_15 | AC | 130 ms
77,576 KB |
testcase_16 | AC | 122 ms
77,304 KB |
testcase_17 | AC | 127 ms
77,420 KB |
testcase_18 | AC | 106 ms
77,480 KB |
testcase_19 | AC | 127 ms
78,052 KB |
ソースコード
import itertools import sys input = sys.stdin.readline def main(): N = int(input()) *A, = map(int, input().split()) MAX = 10000 cnt = [0]*(MAX+1) for a in A[1:]: cnt[a] += 1 ptr = list(range(MAX+1)) def getnxt(x): while ptr[x] <= MAX and cnt[ptr[x]] == 0: ptr[x] += x return ptr[x] if ptr[x] <= MAX else None def getmin(v): maxv = ans = MAX * MAX for i in itertools.count(1): if i*i > v: return ans if v % i == 0: n = getnxt(i) if n is not None: l = n * (v // i) if maxv > l: maxv = l ans = n elif maxv == l: ans = min(ans, n) n = getnxt(v // i) if n is not None: l = n * i if maxv > l: maxv = l ans = n elif maxv == l: ans = min(ans, n) ans = [A[0]] while len(ans) != N: ret = getmin(ans[-1]) ans.append(ret) cnt[ret] -= 1 print(*ans, sep=' ') if __name__ == '__main__': main()