結果

問題 No.14 最小公倍数ソート
ユーザー TKTYITKTYI
提出日時 2021-08-29 01:28:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 70 ms / 5,000 ms
コード長 1,611 bytes
コンパイル時間 4,024 ms
コンパイル使用メモリ 236,620 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-01 19:15:37
合計ジャッジ時間 5,490 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,812 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 5 ms
6,944 KB
testcase_04 AC 65 ms
6,940 KB
testcase_05 AC 30 ms
6,940 KB
testcase_06 AC 32 ms
6,940 KB
testcase_07 AC 41 ms
6,944 KB
testcase_08 AC 51 ms
6,940 KB
testcase_09 AC 65 ms
6,940 KB
testcase_10 AC 63 ms
6,940 KB
testcase_11 AC 65 ms
6,940 KB
testcase_12 AC 62 ms
6,944 KB
testcase_13 AC 70 ms
6,940 KB
testcase_14 AC 64 ms
6,944 KB
testcase_15 AC 62 ms
6,944 KB
testcase_16 AC 33 ms
6,944 KB
testcase_17 AC 27 ms
6,940 KB
testcase_18 AC 16 ms
6,944 KB
testcase_19 AC 51 ms
6,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/vector:65,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/queue:61,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/x86_64-pc-linux-gnu/bits/stdc++.h:86,
                 from main.cpp:1:
In member function 'void std::_Bit_iterator_base::_M_incr(std::ptrdiff_t)',
    inlined from 'std::_Bit_iterator::iterator& std::_Bit_iterator::operator+=(std::iterator<std::random_access_iterator_tag, bool>::difference_type)' at /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_bvector.h:328:14,
    inlined from 'std::_Bit_iterator::iterator std::operator+(const _Bit_iterator::iterator&, iterator<random_access_iterator_tag, bool>::difference_type)' at /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_bvector.h:350:16,
    inlined from 'std::_Bit_iterator::reference std::_Bit_iterator::operator[](std::iterator<std::random_access_iterator_tag, bool>::difference_type) const' at /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_bvector.h:343:24,
    inlined from 'std::vector<bool, _Alloc>::reference std::vector<bool, _Alloc>::operator[](size_type) [with _Alloc = std::allocator<bool>]' at /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_bvector.h:1036:23,
    inlined from 'int main()' at main.cpp:42:14:
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_bvector.h:199:19: warning: 'pp' may be used uninitialized [-Wmaybe-uninitialized]
  199 |       _M_p += __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 #

#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