結果

問題 No.14 最小公倍数ソート
ユーザー ninoinuininoinui
提出日時 2020-07-21 15:00:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,909 ms / 5,000 ms
コード長 658 bytes
コンパイル時間 2,077 ms
コンパイル使用メモリ 201,344 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-28 14:38:02
合計ジャッジ時間 34,704 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 31 ms
4,376 KB
testcase_04 AC 2,909 ms
4,376 KB
testcase_05 AC 970 ms
4,376 KB
testcase_06 AC 1,136 ms
4,376 KB
testcase_07 AC 1,483 ms
4,376 KB
testcase_08 AC 1,952 ms
4,380 KB
testcase_09 AC 2,647 ms
4,376 KB
testcase_10 AC 2,609 ms
4,380 KB
testcase_11 AC 2,702 ms
4,380 KB
testcase_12 AC 2,764 ms
4,380 KB
testcase_13 AC 2,807 ms
4,376 KB
testcase_14 AC 2,727 ms
4,376 KB
testcase_15 AC 2,832 ms
4,376 KB
testcase_16 AC 1,050 ms
4,376 KB
testcase_17 AC 746 ms
4,376 KB
testcase_18 AC 334 ms
4,376 KB
testcase_19 AC 1,764 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (auto &a : A) cin >> a;
  vector<int> ans;
  ans.push_back(A.at(0));
  int now = A.at(0);
  A.erase(A.begin() + 0);
  while (A.size()) {
    int ni = 0;
    for (long i = 0, mxl = 1e10+1, mxa = 1e5+1; i < A.size(); i++) {
      long l = lcm(now, A.at(i));
      if (l < mxl) mxl = l, mxa = A.at(i), ni = i;
      else if (l == mxl && A.at(i) < mxa) mxa = A.at(i), ni = i;
    }
    ans.push_back(A.at(ni));
    now = A.at(ni);
    A.erase(A.begin() + ni);
  }
  for (int i = 0; i < N; i++) {
    cout << ans.at(i) << ((i == N - 1) ? "\n" : " ");
  }
}
0