結果

問題 No.14 最小公倍数ソート
ユーザー szkhtsszkhts
提出日時 2021-01-11 11:10:15
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 601 bytes
コンパイル時間 110 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 22,528 KB
最終ジャッジ日時 2024-05-01 06:44:53
合計ジャッジ時間 7,589 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 26 ms
10,624 KB
testcase_03 WA -
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 #

def gdc(a, b):
    if b == 0:
        return a
    else:
        return gdc(b, a % b)


if __name__ == '__main__':
    N = int(input())
    a = list(map(int, input().split()))
    
    for i in range(N - 1):
        idx = 0
        low_value = 999999
        for j in range(i + 1, N):
            d = gdc(a[i], a[j])
            lcm = a[i] / d * a[j]

            if(low_value >= lcm):
                low_value = lcm
                if a[j] < a[idx]:
                    idx = j
        
        temp = a[i + 1]
        a[i + 1] = a[idx]
        a[idx] = temp
        
    print(' '.join(map(str,a)))
0