結果

問題 No.14 最小公倍数ソート
ユーザー cureskolcureskol
提出日時 2022-05-28 17:57:09
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 146 ms / 5,000 ms
コード長 1,391 bytes
コンパイル時間 2,367 ms
コンパイル使用メモリ 201,608 KB
実行使用メモリ 8,176 KB
最終ジャッジ日時 2023-10-20 23:28:39
合計ジャッジ時間 6,034 ms
ジャッジサーバーID
(参考情報)
judge9 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 95 ms
4,380 KB
testcase_01 AC 95 ms
4,380 KB
testcase_02 AC 95 ms
4,380 KB
testcase_03 AC 101 ms
5,008 KB
testcase_04 AC 144 ms
8,176 KB
testcase_05 AC 120 ms
6,520 KB
testcase_06 AC 124 ms
6,816 KB
testcase_07 AC 129 ms
7,192 KB
testcase_08 AC 135 ms
7,588 KB
testcase_09 AC 141 ms
8,048 KB
testcase_10 AC 141 ms
8,040 KB
testcase_11 AC 142 ms
8,104 KB
testcase_12 AC 144 ms
8,128 KB
testcase_13 AC 146 ms
8,124 KB
testcase_14 AC 144 ms
8,108 KB
testcase_15 AC 146 ms
8,148 KB
testcase_16 AC 129 ms
7,172 KB
testcase_17 AC 123 ms
6,836 KB
testcase_18 AC 115 ms
6,184 KB
testcase_19 AC 136 ms
7,684 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#ifdef __LOCAL
 #include <debug>
#else
 #define debug(...) void(0)
#endif

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()

template<typename T>
istream& operator>>(istream&is,vector<T>&v){
  for(T&p:v)is>>p;
  return is;
}
template<typename T>
ostream& operator<<(ostream&os,const vector<T>&v){
  if(&os==&cerr)os<<"[";
  for(int i=0;i<v.size();i++){
    os<<v[i];
    if(i+1<v.size())os<<(&os==&cerr?",":" ");
  }
  if(&os==&cerr)os<<"]";
  return os;
}

template<typename T>
bool chmin(T &a,T b){
  return (a>b&&(a=b,true));
}

vector<vector<int>> pr(10000);

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  
  for(int i=1;i<=10000;i++)
    for(int j=i;j<=10000;j+=i)
      pr[j].push_back(i);
  for(int i=1;i<=10000;i++)reverse(ALL(pr));

  int n;cin>>n;
  vector<int> ans(n);
  cin>>ans[0];
  map<int,set<int>> mp;
  map<int,int> memo;
  REP(_,n-1){
    int b;cin>>b;
    if(memo[b]++)continue;
    for(int p:pr[b])mp[p].insert(b);
  }
  for(int i=1;i<n;i++){
    int mn=1e9,val;
    for(int p:pr[ans[i-1]]){
      if(!mp.count(p))continue;
      int A=*mp[p].begin();
      if(chmin(mn,ans[i-1]*A/p))val=A;
    }
    REP(_,memo[val])ans[i++]=val;i--;
    for(int p:pr[val]){
      mp[p].erase(val);
      if(!mp[p].size())mp.erase(p);
    }
  }
  cout<<ans<<endl;
}

0