結果

問題 No.14 最小公倍数ソート
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2017-06-11 14:13:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,512 bytes
コンパイル時間 1,427 ms
コンパイル使用メモリ 166,764 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 20:59:59
合計ジャッジ時間 53,000 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 WA -
testcase_02 AC 2 ms
4,348 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
using namespace std; void _main(); int main(){cin.tie(0);ios::sync_with_stdio(0);_main();}
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧  
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     
    /   \     | |     
    /   / ̄ ̄ ̄ ̄/  |  
  __(__ニつ/     _/ .| .|____  
     \/____/ (u ⊃  
---------------------------------------------------------------------------------------------------*/


int gcd(int a, int b) { return a ? gcd(b%a, a) : b; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
int N, A[10101];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    rep(i, 0, N) cin >> A[i];

    rep(i, 0, N) {
        if (0 < i) printf(" ");
        printf("%d", A[i]);

        int mi = i + 1, lc = lcm(A[i], A[i + 1]);
        rep(j, i + 2, N) {
            int x = lcm(A[i], A[j]);
            if (x < lc) {
                mi = j, lc = x;
            } else if (x == lc && A[j] < A[i]) {
                mi = j, lc = x;
            }
        }
        swap(A[i + 1], A[mi]);
    }
    printf("\n");
}
0