結果

問題 No.14 最小公倍数ソート
ユーザー imgry22imgry22
提出日時 2015-01-25 23:17:25
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 4,656 ms / 5,000 ms
コード長 1,367 bytes
コンパイル時間 1,890 ms
コンパイル使用メモリ 144,636 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-05 06:33:20
合計ジャッジ時間 53,637 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 49 ms
4,376 KB
testcase_04 AC 4,656 ms
4,380 KB
testcase_05 AC 1,562 ms
4,380 KB
testcase_06 AC 1,825 ms
4,376 KB
testcase_07 AC 2,380 ms
4,376 KB
testcase_08 AC 3,133 ms
4,380 KB
testcase_09 AC 4,241 ms
4,376 KB
testcase_10 AC 4,163 ms
4,380 KB
testcase_11 AC 4,324 ms
4,380 KB
testcase_12 AC 4,451 ms
4,376 KB
testcase_13 AC 4,499 ms
4,376 KB
testcase_14 AC 4,380 ms
4,376 KB
testcase_15 AC 4,516 ms
4,376 KB
testcase_16 AC 1,683 ms
4,376 KB
testcase_17 AC 1,198 ms
4,376 KB
testcase_18 AC 532 ms
4,376 KB
testcase_19 AC 2,833 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;

#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair#define pb            push_back
template<class T1, class T2> inline void minup(T1& m, T2 x){ if(m>x) m=static_cast<T2>(x); }
template<class T1, class T2> inline void maxup(T1& m, T2 x){ if(m<x) m=static_cast<T2>(x); }

#define INF 1000000000
#define MOD 1000000009
#define EPS 1E-9

template<class T> T gcd(T a, T b)
{
  T tmp;

  while(b){
    tmp = a;
    a = b;
    b = tmp%b;
  }

  return a;
}

template<class T> inline T lcm(T a, T b){ return a * (b / gcd(a, b)); }

const int MAX_N = 10000;
int n;
int a[MAX_N];
int tmp;

int main()
{
  cin >> n;
  rep(i, n) cin >> a[i];

  rrep(i, 1, n-1){
    int mn = lcm(a[i-1], a[i]);
    int k = i;
    rrep(j, i+1, n){
      tmp = lcm(a[i-1], a[j]);
      if(mn > tmp || mn == tmp && a[k] > a[j]){
        mn = tmp;
        k = j;
      }
    }
    swap(a[i], a[k]);
  }

  rep(i, n) cout << a[i] << " ";  cout << endl;

  return 0;
}
0