結果

問題 No.14 最小公倍数ソート
ユーザー szkhtsszkhts
提出日時 2022-08-07 08:12:04
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 771 bytes
コンパイル時間 93 ms
コンパイル使用メモリ 11,936 KB
実行使用メモリ 15,772 KB
最終ジャッジ日時 2023-10-17 04:17:14
合計ジャッジ時間 8,080 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
10,220 KB
testcase_01 AC 29 ms
10,220 KB
testcase_02 AC 34 ms
10,220 KB
testcase_03 AC 724 ms
10,352 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
A = list(map(int, input().split()))

dp = [0] * 10001
m = [0] * 10001
ret = []

for i in range(N):
    m[A[i]] += 1

next = A[0]
ret.append(next)
m[next] -= 1

for i in range(N - 1):
    divisor = []
    for j in range(1, next + 1):
        if next % j == 0:
            divisor.append(j)
            if j * j != next:
                divisor.append(next // j)

    divisor.sort()
    check = 99999
    ans = 0
    for d in divisor:
        while d * dp[d] <= 10000:
            if m[d * dp[d]]:
                if dp[d] < check:
                    ans = d * dp[d]
                    check = dp[d]
                break
            else:
                dp[d] += 1

    next = ans
    ret.append(next)
    m[next] -= 1

print(' '.join(map(str, ret)))

0