結果

問題 No.14 最小公倍数ソート
コンテスト
ユーザー TKTYI
提出日時 2021-08-29 01:28:42
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 33 ms / 5,000 ms
コード長 1,611 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,126 ms
コンパイル使用メモリ 254,720 KB
実行使用メモリ 7,972 KB
最終ジャッジ日時 2026-05-16 05:15:09
合計ジャッジ時間 4,778 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 20
権限があれば一括ダウンロードができます
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/vector:69,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/queue:69,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/x86_64-pc-linux-gnu/bits/stdc++.h:160,
                 from main.cpp:1:
In member function 'std::vector<bool, _Alloc>::reference std::vector<bool, _Alloc>::operator[](size_type) [with _Alloc = std::allocator<bool>]',
    inlined from 'int main()' at main.cpp:42:14:
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/stl_bvector.h:1161:43: warning: 'pp' may be used uninitialized [-Wmaybe-uninitialized]
 1161 |                                1UL << __n % int(_S_word_bit));
      |                                       ~~~~^~~~~~~~~~~~~~~~~~
main.cpp: In function 'int main()':
main.cpp:35:8: note: 'pp' was declared here
   35 |     ll pp,m=1e18;
      |        ^~

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long int ll;
typedef long double ld;
#define FOR(i,l,r) for(ll i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,l,r) for(ll i=r-1;i>=l;i--)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define P pair<ll,ll>
#define F first
#define S second
#define BS(A,x) binary_search(ALL(A),x)
#define LB(A,x) (ll)(lower_bound(ALL(A),x)-A.begin())
#define UB(A,x) (ll)(upper_bound(ALL(A),x)-A.begin())
#define COU(A,x) UB(A,x)-LB(A,x)
template<typename T>using min_priority_queue=priority_queue<T,vector<T>,greater<T>>;
using mint=modint1000000007;
signed main(){
  ll N;cin>>N;vector<ll>A(N);vector<vector<ll>>D(N,vector<ll>());
  REP(i,N)cin>>A[i];sort(A.begin()+1,A.end());
  REP(i,N){
    ll d=1;while(d*d<A[i]){if(A[i]%d==0){D[i].push_back(d);D[i].push_back(A[i]/d);}d++;}
    if(d*d==A[i])D[i].push_back(d);sort(ALL(D[i]));
  }
  vector<ll>d,dd;REP(i,N)REP(j,D[i].size())d.push_back(D[i][j]);sort(ALL(d));
  REP(i,d.size())if(i==0||d[i]!=d[i-1])dd.push_back(d[i]);
  REP(i,N)REP(j,D[i].size())D[i][j]=LB(dd,D[i][j]);
  vector<vector<ll>>Q(dd.size(),vector<ll>());
  REP(i,N)REP(j,D[i].size())Q[D[i][j]].push_back(i);
  vector<bool>X(N,1);X[0]=0;ll p=0;cout<<A[p];
  REP(i,N-1){
    ll pp,m=1e18;
    REP(j,D[p].size()){
      ll k=0;while(k<Q[D[p][j]].size()&&!X[Q[D[p][j]][k]])k++;
      if(k<Q[D[p][j]].size()&&m>A[Q[D[p][j]][k]]/dd[D[p][j]]){
        m=A[Q[D[p][j]][k]]/dd[D[p][j]];pp=Q[D[p][j]][k];
      }
    }
    p=pp;X[pp]=0;
    cout<<" "<<A[p];
  }
  cout<<endl;
  return 0;
}
0