結果

問題 No.14 最小公倍数ソート
ユーザー pluto77pluto77
提出日時 2017-12-03 11:23:12
言語 C++11
(gcc 11.4.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 540 bytes
コンパイル時間 1,702 ms
コンパイル使用メモリ 68,152 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-08-18 22:51:32
合計ジャッジ時間 64,941 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int gcd(int x,int y){
 while(y!=0){
  int temp=x%y;
  x=y;
  y=temp;
 }
 return x;
}

int lcm(int x, int y){
 return x/gcd(x,y)*y;
}

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