結果

問題 No.14 最小公倍数ソート
ユーザー EmKjpEmKjp
提出日時 2015-02-21 15:41:45
言語 C++11
(gcc 13.3.0)
結果
TLE  
実行時間 -
コード長 1,229 bytes
コンパイル時間 615 ms
コンパイル使用メモリ 83,360 KB
実行使用メモリ 10,148 KB
最終ジャッジ日時 2024-06-23 21:36:38
合計ジャッジ時間 7,216 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 4 TLE * 1 -- * 15
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:35:19: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   35 |     FOR(i,n) scanf("%d",&a[i]);
      |              ~~~~~^~~~~~~~~~~~

ソースコード

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