結果

問題 No.14 最小公倍数ソート
ユーザー SakaTakuSakaTaku
提出日時 2020-09-21 17:01:24
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,095 bytes
コンパイル時間 2,009 ms
コンパイル使用メモリ 206,188 KB
実行使用メモリ 12,828 KB
最終ジャッジ日時 2023-09-06 17:20:27
合計ジャッジ時間 3,947 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
8,104 KB
testcase_01 AC 3 ms
8,000 KB
testcase_02 AC 4 ms
8,056 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 <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < n; ++i)
using ll = long long;
using P = pair<int,int>;
multiset<int> A[100001];
int main() {
   int N;cin>>N;
   vector<int>a(N);
   rep(i,N)cin>>a[i];
   rep(i,N){
      int ai=a[i];
      for (int j = 1; j*j <= ai; j++){
         if(ai%j==0){
            A[j].insert(ai/j);
            if(j*j==ai)continue;
            A[ai/j].insert(j);
         }
      }
   }
   vector<int> ans;
   ans.push_back(a[0]);
   rep(i,N-1){
      int ai=ans[i];
      int mini=1e9, next;
      int j=1;
      for (; j*j <= ai; j++){
         A[j].extract(ai/j);
         if(!A[j].empty()){
            if(mini>*A[j].begin()){
               mini=*A[j].begin();
               next=mini*j;
            }
         }
      }
      for (; j*j >= 1; j--){
         A[ai/j].extract(j);
         if(!A[ai/j].empty()){
            if(mini>*A[ai/j].begin()){
               mini=*A[ai/j].begin();
               next=mini*ai/j;
            }
         }
      }
      ans.push_back(next);
   }
   rep(i,N)cout<<ans[i]<<" ";
   cout<<endl;
}
0