結果

問題 No.14 最小公倍数ソート
ユーザー goodbatongoodbaton
提出日時 2015-07-28 21:44:53
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 4,344 ms / 5,000 ms
コード長 1,214 bytes
コンパイル時間 561 ms
コンパイル使用メモリ 75,248 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-24 12:30:37
合計ジャッジ時間 48,179 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 45 ms
4,376 KB
testcase_04 AC 4,344 ms
4,376 KB
testcase_05 AC 1,458 ms
4,380 KB
testcase_06 AC 1,708 ms
4,380 KB
testcase_07 AC 2,209 ms
4,380 KB
testcase_08 AC 2,910 ms
4,376 KB
testcase_09 AC 3,945 ms
4,376 KB
testcase_10 AC 3,847 ms
4,376 KB
testcase_11 AC 4,066 ms
4,376 KB
testcase_12 AC 4,128 ms
4,376 KB
testcase_13 AC 4,159 ms
4,376 KB
testcase_14 AC 4,045 ms
4,380 KB
testcase_15 AC 4,139 ms
4,376 KB
testcase_16 AC 1,550 ms
4,376 KB
testcase_17 AC 1,113 ms
4,380 KB
testcase_18 AC 489 ms
4,380 KB
testcase_19 AC 2,585 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:34:31: warning: ‘mini’ may be used uninitialized in this function [-Wmaybe-uninitialized]
     int n,a[SIZE],minlcm,mina,mini,l;
                               ^~~~

ソースコード

diff #

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cstring>

typedef long long ll;
using namespace std;

#define mod 1000003
#define INF 1000000000
#define LLINF 2000000000000000000LL

#define SIZE 10000

int gcd(int a,int b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}

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

int main(){
    int n,a[SIZE],minlcm,mina,mini,l;
    vector<int> ans;
    
    scanf("%d",&n);
    
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    
    ans.push_back(a[0]);
    
    for(int i=0;i<n-1;i++){
        
        minlcm = mina = INF;
        
        for(int j=i+1;j<n;j++){
            
            l = lcm(a[i],a[j]);
            
            if(minlcm>l || (minlcm==l && mina>a[j])){
                minlcm = l;
                mina = a[j];
                mini = j;
            }
        }
        
        ans.push_back(a[mini]);
        swap(a[mini],a[i+1]);
        
    }
    
    for(int i=0;i<ans.size();i++){
        printf(i<ans.size()-1?"%d ":"%d\n",ans[i]);
    }
    
    return 0;
}
0