結果

問題 No.14 最小公倍数ソート
ユーザー szkhtsszkhts
提出日時 2021-01-24 09:50:08
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 737 bytes
コンパイル時間 100 ms
コンパイル使用メモリ 10,944 KB
実行使用メモリ 13,788 KB
最終ジャッジ日時 2023-08-30 18:54:19
合計ジャッジ時間 7,601 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,876 KB
testcase_01 AC 15 ms
7,796 KB
testcase_02 AC 15 ms
7,852 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
        a = a[:i + 1] + sorted(a[i + 1:])
#        print(a)
        for j in range(i + 1, N):
            d = gdc(a[i], a[j])
            lcm = a[i] / d * a[j]
#            print('a[{}]:{},a[{}]:{},lcm:{}'.format(i, a[i], j, a[j], lcm))
            
            if(low_value > lcm):
                low_value = lcm
                idx = j

        if idx != 0:
            temp = a[i + 1]
            a[i + 1] = a[idx]
            a[idx] = temp
        
    print(' '.join(map(str,a)))
0