結果

問題 No.14 最小公倍数ソート
ユーザー どららどらら
提出日時 2015-06-02 22:15:02
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,352 bytes
コンパイル時間 901 ms
コンパイル使用メモリ 87,708 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-20 18:54:57
合計ジャッジ時間 1,903 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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;


vector<int> factorize(int x){
  vector<int> ret;
  int d, q;
  while(x>=4 && x%2==0){ret.push_back(2); x/=2;}
  d = 3; q = x/d;
  while(q>=d){
    if(x%d==0){ ret.push_back(d); x=q; }else{ d+=2; }
    q=x/d;
  }
  ret.push_back(x);
  sort(ALLOF(ret));
  return ret;
}

struct ST {
  int a;
  vector<int> fact;
};
bool operator<(const ST& a, const ST& b){
  int i=0;
  while(i<a.fact.size() && i<b.fact.size()){
    if(a.fact[i] < b.fact[i]) return true;
    if(a.fact[i] > b.fact[i]) return false;
    i++;
  }
  return a.fact.size() < b.fact.size();
}

int main(){
  ios::sync_with_stdio(false);
  
  int N, a;
  vector<ST> ret;
  cin >> N;
  rep(i,N){
    cin >> a;
    ret.push_back((ST){a,factorize(a)});
  }

  sort(ret.begin()+1, ret.end());
  
  rep(i,ret.size()){
    if(i!=0) cout << " ";
    cout << ret[i].a;
  }
  cout << endl;
  
  return 0;
}
0