結果
問題 | No.14 最小公倍数ソート |
ユーザー | zimpha |
提出日時 | 2017-12-07 21:23:43 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 529 bytes |
コンパイル時間 | 440 ms |
コンパイル使用メモリ | 86,944 KB |
実行使用メモリ | 92,896 KB |
最終ジャッジ日時 | 2023-08-19 12:22:44 |
合計ジャッジ時間 | 22,337 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 76 ms
70,976 KB |
testcase_01 | AC | 76 ms
71,296 KB |
testcase_02 | AC | 76 ms
71,200 KB |
testcase_03 | AC | 614 ms
90,836 KB |
testcase_04 | TLE | - |
testcase_05 | AC | 2,314 ms
88,760 KB |
testcase_06 | AC | 2,399 ms
92,896 KB |
testcase_07 | AC | 2,991 ms
92,504 KB |
testcase_08 | TLE | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
ソースコード
upp = 1000 mem = [[-1] * upp for i in range(upp)] def fast_gcd(x, y): if x < upp and y < upp and mem[x][y] != -1: return mem[x][y] gcd = x if not y else fast_gcd(y, x % y) if x < upp and y < upp: mem[x][y] = gcd return gcd n = int(input()) a = list(map(int, input().split())) for i in range(n - 1): x = i + 1 r = a[x] / fast_gcd(a[i], a[x]) for j in range(i + 2, n): t = a[j] / fast_gcd(a[i], a[j]) if t < r or (t == r and a[j] < a[x]): r, x = t, j a[i + 1], a[x] = a[x], a[i + 1] print(*a)