結果

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

テストケース

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

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