結果

問題 No.14 最小公倍数ソート
ユーザー mamekinmamekin
提出日時 2015-01-11 22:37:01
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3,233 ms / 5,000 ms
コード長 1,150 bytes
コンパイル時間 2,177 ms
コンパイル使用メモリ 97,696 KB
実行使用メモリ 7,592 KB
最終ジャッジ日時 2023-09-03 23:25:47
合計ジャッジ時間 39,605 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
7,240 KB
testcase_01 AC 4 ms
7,296 KB
testcase_02 AC 4 ms
7,272 KB
testcase_03 AC 46 ms
7,284 KB
testcase_04 AC 3,233 ms
7,376 KB
testcase_05 AC 1,078 ms
7,296 KB
testcase_06 AC 1,275 ms
7,592 KB
testcase_07 AC 1,664 ms
7,344 KB
testcase_08 AC 2,168 ms
7,580 KB
testcase_09 AC 2,909 ms
7,340 KB
testcase_10 AC 2,867 ms
7,312 KB
testcase_11 AC 2,968 ms
7,320 KB
testcase_12 AC 3,072 ms
7,364 KB
testcase_13 AC 3,093 ms
7,464 KB
testcase_14 AC 3,023 ms
7,320 KB
testcase_15 AC 3,143 ms
7,352 KB
testcase_16 AC 1,295 ms
7,332 KB
testcase_17 AC 930 ms
7,300 KB
testcase_18 AC 398 ms
7,308 KB
testcase_19 AC 2,006 ms
7,344 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(1000, vector<int>(1000, -1));

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

    int ret = gcd(b, a % b);
    if(a < 1000 && b < 1000)
        memo[a][b] = ret;
    return ret;
}

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