結果

問題 No.14 最小公倍数ソート
ユーザー どららどらら
提出日時 2015-06-02 21:37:33
言語 C++11
(gcc 11.4.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,036 bytes
コンパイル時間 671 ms
コンパイル使用メモリ 80,416 KB
実行使用メモリ 8,760 KB
最終ジャッジ日時 2023-09-20 18:52:07
合計ジャッジ時間 7,525 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 66 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 <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <iostream>
#include <queue>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;

int gcd(int a, int b){return (b==0?a:gcd(b,a%b));}
int lcm(int a, int b){return a/gcd(a,b)*b;}

struct ST {
  int a, b;
};
bool operator<(const ST& a, const ST& b){
  if(a.b==b.b) return a.a<b.a;
  return a.b<b.b;
}

int main(){
  int N, a;
  vector<ST> A;
  cin >> N;
  rep(i,N){
    cin >> a;
    A.push_back((ST){a,a});
  }

  rep(i,N){
    REP(j,i+1,N){
      A[j].b = lcm(A[i].a, A[j].a);
    }
    sort(A.begin()+i+1,A.end());
  }
  
  rep(i,A.size()){
    if(i!=0) cout << " ";
    cout << A[i].a;
  }
  cout << endl;
  
  return 0;
}
0