結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,320 KB
testcase_01 AC 3 ms
8,068 KB
testcase_02 AC 3 ms
8,108 KB
testcase_03 AC 7 ms
8,484 KB
testcase_04 WA -
testcase_05 AC 26 ms
10,776 KB
testcase_06 AC 29 ms
10,852 KB
testcase_07 AC 34 ms
11,292 KB
testcase_08 AC 39 ms
11,808 KB
testcase_09 WA -
testcase_10 AC 47 ms
12,280 KB
testcase_11 AC 48 ms
12,456 KB
testcase_12 AC 48 ms
12,416 KB
testcase_13 AC 49 ms
12,468 KB
testcase_14 AC 47 ms
12,548 KB
testcase_15 AC 51 ms
12,640 KB
testcase_16 AC 31 ms
10,832 KB
testcase_17 AC 27 ms
10,488 KB
testcase_18 AC 17 ms
9,664 KB
testcase_19 AC 38 ms
11,684 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;
               }
            }
         }
      }
      if(j*j==ai)j--;
      for (; j*j >= 1; j--){
         if(ai%j==0){
            int bi=ai/j;
            A[bi].extract(j);
            if(!A[bi].empty()){
               if(mini>*A[bi].begin()){
                  mini=*A[bi].begin();
                  next=mini*bi;
               }
            }
         }
      }
      ans.push_back(next);
   }
   rep(i,N)cout<<ans[i]<<" ";
   cout<<endl;
}
0