結果

問題 No.14 最小公倍数ソート
ユーザー mamekinmamekin
提出日時 2015-01-11 22:34:54
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 4,500 ms / 5,000 ms
コード長 1,067 bytes
コンパイル時間 1,938 ms
コンパイル使用メモリ 97,028 KB
実行使用メモリ 394,428 KB
最終ジャッジ日時 2023-09-03 23:22:59
合計ジャッジ時間 55,485 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 287 ms
393,904 KB
testcase_01 AC 287 ms
393,888 KB
testcase_02 AC 289 ms
393,888 KB
testcase_03 AC 363 ms
393,756 KB
testcase_04 AC 4,500 ms
394,244 KB
testcase_05 AC 1,612 ms
394,328 KB
testcase_06 AC 1,914 ms
394,192 KB
testcase_07 AC 2,519 ms
394,428 KB
testcase_08 AC 3,223 ms
394,344 KB
testcase_09 AC 4,214 ms
394,184 KB
testcase_10 AC 4,096 ms
394,340 KB
testcase_11 AC 4,169 ms
394,240 KB
testcase_12 AC 4,259 ms
394,192 KB
testcase_13 AC 4,287 ms
394,428 KB
testcase_14 AC 4,235 ms
394,244 KB
testcase_15 AC 4,286 ms
394,268 KB
testcase_16 AC 2,075 ms
393,760 KB
testcase_17 AC 1,641 ms
393,760 KB
testcase_18 AC 926 ms
393,804 KB
testcase_19 AC 3,016 ms
394,236 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;

vector<vector<int> > memo(10001, vector<int>(10001, -1));

int gcd(int a, int b){
    if(b == 0)
        return a;
    if(memo[a][b] != -1)
        return memo[a][b];

    return memo[a][b] = gcd(b, a % b);
}

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