結果

問題 No.14 最小公倍数ソート
ユーザー EmKjpEmKjp
提出日時 2015-02-21 15:41:45
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,229 bytes
コンパイル時間 1,139 ms
コンパイル使用メモリ 77,956 KB
実行使用メモリ 8,752 KB
最終ジャッジ日時 2023-09-06 02:45:27
合計ジャッジ時間 7,516 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<numeric>
#include<functional>
#include<complex>

using namespace std;
#define BET(a,b,c) ((a)<=(b)&&(b)<(c))
#define FOR(i,n) for(int i=0,i##_end=(int(n));i<i##_end;i++)
#define SZ(x) (int)(x.size())
#define ALL(x) (x).begin(),(x).end()
#define MP make_pair
#define FOR_EACH(it,v) for(__typeof(v.begin()) it=v.begin(),it_end=v.end() ; it != it_end ; it++)
typedef vector<int> VI;
typedef vector<VI> VVI;

long long gcd (long long s , long long t) { return t ? gcd(t,s%t) : s ; }
long long lcm (long long s , long long t) { return s / gcd(s, t) * t; }

int main()
{
    int n;
    cin>>n;
    VI a(n);
    FOR(i,n) scanf("%d",&a[i]);
    for(int i=0;i<n;i++){
        int x = a[i];
        long long minLcm = 1LL<<62;
        for(int j=i+1;j<n;j++){
            long long l = lcm(x, a[j]);
            if(l < minLcm || (l == minLcm && a[i+1] > a[j])){
                minLcm = l;
                swap(a[i+1], a[j]);
            }
        }
    }
    FOR(i,n) printf("%s%d",i?" ":"",a[i]);
    puts("");
    return 0;
}
0