結果

問題 No.14 最小公倍数ソート
ユーザー Mao-betaMao-beta
提出日時 2024-02-29 01:14:19
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,062 bytes
コンパイル時間 311 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 77,032 KB
最終ジャッジ日時 2024-02-29 01:15:23
合計ジャッジ時間 62,329 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
55,752 KB
testcase_01 AC 47 ms
55,752 KB
testcase_02 AC 59 ms
55,752 KB
testcase_03 AC 115 ms
66,508 KB
testcase_04 TLE -
testcase_05 AC 1,955 ms
73,204 KB
testcase_06 AC 2,231 ms
73,832 KB
testcase_07 AC 2,877 ms
74,344 KB
testcase_08 AC 3,771 ms
76,776 KB
testcase_09 TLE -
testcase_10 TLE -
testcase_11 TLE -
testcase_12 TLE -
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 AC 2,014 ms
73,580 KB
testcase_17 AC 1,450 ms
72,956 KB
testcase_18 AC 683 ms
72,992 KB
testcase_19 AC 3,351 ms
76,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import math
import bisect
from heapq import heapify, heappop, heappush
from collections import deque, defaultdict, Counter
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
MOD99 = 998244353

input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()
SMI = lambda: input().split()
SLI = lambda: list(SMI())
EI = lambda m: [NLI() for _ in range(m)]


def main():
    N = NI()
    A = NLI()
    for i in range(N-1):
        L = 10**10
        nj = N-1
        na = 10**10
        for j in range(N-1, i, -1):
            l = A[i] * A[j] // math.gcd(A[i], A[j])
            if l < L:
                L = l
                nj = j
                na = A[j]
            elif l == L and A[j] < na:
                nj = j
                na = A[j]
        A[i+1], A[nj] = A[nj], A[i+1]
        # print(A)
    print(*A)


if __name__ == "__main__":
    main()
0