結果

問題 No.14 最小公倍数ソート
ユーザー yuki2006yuki2006
提出日時 2014-10-28 17:00:32
言語 Python2
(2.7.18)
結果
TLE  
実行時間 -
コード長 748 bytes
コンパイル時間 249 ms
コンパイル使用メモリ 6,696 KB
実行使用メモリ 6,012 KB
最終ジャッジ日時 2023-08-28 23:18:02
合計ジャッジ時間 7,583 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
6,008 KB
testcase_01 AC 10 ms
5,944 KB
testcase_02 AC 11 ms
6,008 KB
testcase_03 AC 431 ms
6,012 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 #

# -*- coding: utf-8 -*-

def solve(N, data):
    def gcd(a, b):
        while b > 0:
            a, b = b, a % b
        return a

    def bcd(a, b):
        return a * b / gcd(a, b)

    result = [0] * N
    result[0] = data[0]
    data[0] = -1
    ans_p = 1
    while ans_p < N:
        mn = -1
        index = 0
        for i, v in enumerate(data):
            a = bcd(result[ans_p - 1], v)
            if mn == -1 or mn > a or (mn == a and data[index] > v):
                mn = a
                index = i

        result[ans_p] = data[index]
        ans_p += 1
        del data[index]
    return result


N = int(raw_input())
data = map(int, raw_input().split(" "))

print " ".join(map(str, solve(N, data)))
0