結果

問題 No.14 最小公倍数ソート
ユーザー nebukuro09nebukuro09
提出日時 2016-11-10 16:56:34
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 3,292 ms / 5,000 ms
コード長 634 bytes
コンパイル時間 671 ms
コンパイル使用メモリ 104,772 KB
実行使用メモリ 4,836 KB
最終ジャッジ日時 2023-09-02 22:51:53
合計ジャッジ時間 37,695 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,368 KB
testcase_01 AC 1 ms
4,372 KB
testcase_02 AC 1 ms
4,368 KB
testcase_03 AC 35 ms
4,368 KB
testcase_04 AC 3,292 ms
4,372 KB
testcase_05 AC 1,101 ms
4,368 KB
testcase_06 AC 1,294 ms
4,836 KB
testcase_07 AC 1,685 ms
4,372 KB
testcase_08 AC 2,226 ms
4,372 KB
testcase_09 AC 3,029 ms
4,372 KB
testcase_10 AC 3,005 ms
4,368 KB
testcase_11 AC 3,066 ms
4,368 KB
testcase_12 AC 3,141 ms
4,368 KB
testcase_13 AC 3,180 ms
4,372 KB
testcase_14 AC 3,081 ms
4,368 KB
testcase_15 AC 3,206 ms
4,372 KB
testcase_16 AC 1,194 ms
4,368 KB
testcase_17 AC 851 ms
4,368 KB
testcase_18 AC 382 ms
4,372 KB
testcase_19 AC 2,001 ms
4,368 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
/dmd2/linux/bin64/../../src/phobos/std/numeric.d(2999): Warning: cannot inline function `std.numeric.gcdImpl!uint.gcdImpl`

ソースコード

diff #

import std.stdio;
import std.array;
import std.string;
import std.conv;
import std.algorithm;
import std.typecons;
import std.range;
import std.random;
import std.math;
import std.container;
import std.numeric;

void main() {
  int N = readln.chomp.to!int;
  auto A = readln.split.map!(to!int).array;

  foreach (i; 0..N-1) {
    int mv = int.max;
    int mj = -1;
    foreach (j; i+1..N) {
      int lcm = A[i]*A[j]/gcd(A[i], A[j]);
      if (lcm < mv) {
        mv = lcm;
        mj = j;
      }
      else if (lcm == mv && A[mj] > A[j])
        mj = j;
    }
    swap(A[i+1], A[mj]);
  }

  writeln(A.map!(to!string).join(" "));
}
0