結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,088 KB
testcase_01 AC 5 ms
8,144 KB
testcase_02 AC 4 ms
8,056 KB
testcase_03 AC 8 ms
8,480 KB
testcase_04 WA -
testcase_05 AC 28 ms
10,588 KB
testcase_06 AC 31 ms
10,884 KB
testcase_07 AC 36 ms
11,232 KB
testcase_08 AC 41 ms
11,736 KB
testcase_09 WA -
testcase_10 AC 48 ms
12,244 KB
testcase_11 AC 50 ms
12,696 KB
testcase_12 AC 49 ms
12,424 KB
testcase_13 AC 52 ms
12,436 KB
testcase_14 AC 51 ms
12,372 KB
testcase_15 AC 52 ms
12,528 KB
testcase_16 AC 31 ms
10,868 KB
testcase_17 AC 26 ms
10,576 KB
testcase_18 AC 18 ms
9,604 KB
testcase_19 AC 40 ms
11,576 KB
権限があれば一括ダウンロードができます

ソースコード

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++){
         if(ai%j==0){
            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--){
         if(ai%j==0){
            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