結果

問題 No.14 最小公倍数ソート
ユーザー mamekinmamekin
提出日時 2015-01-11 22:01:13
言語 C++11
(gcc 11.4.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 979 bytes
コンパイル時間 3,162 ms
コンパイル使用メモリ 94,140 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-03 23:18:49
合計ジャッジ時間 62,669 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 64 ms
4,380 KB
testcase_04 TLE -
testcase_05 AC 2,011 ms
4,376 KB
testcase_06 AC 2,369 ms
4,376 KB
testcase_07 AC 3,081 ms
4,376 KB
testcase_08 AC 4,038 ms
4,384 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,261 ms
4,384 KB
testcase_17 AC 1,620 ms
4,380 KB
testcase_18 AC 726 ms
4,384 KB
testcase_19 AC 3,727 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

int gcd(int a, int b){
    while(b != 0){
        int tmp = a % b;
        a = b;
        b = tmp;
    }
    return a;
}

int lcm(int a, int b){
    return a / gcd(a, b) * b;
}

int main()
{
    int n;
    cin >> n;
    vector<pair<int, int> > a(n);
    for(int i=0; i<n; ++i)
        cin >> a[i].second;

    for(int i=0; i<n; ++i){
        for(int j=i+1; j<n; ++j)
            a[j].first = lcm(a[i].second, a[j].second);
        sort(a.begin() + i + 1, a.end());
    }

    cout << a[0].second;
    for(int i=1; i<n; ++i)
        cout << ' ' << a[i].second;
    cout << endl;

    return 0;
}
0