結果
問題 |
No.1730 GCD on Blackboard in yukicoder
|
ユーザー |
|
提出日時 | 2023-07-17 19:09:29 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,598 bytes |
コンパイル時間 | 1,460 ms |
コンパイル使用メモリ | 121,208 KB |
最終ジャッジ日時 | 2025-02-15 15:28:03 |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 10 WA * 14 |
ソースコード
#include<iostream> #include<set> #include<algorithm> #include<vector> #include<string> #include<set> #include<map> #include<numeric> #include<queue> #include<cmath> #include <unordered_set> using namespace std; typedef long long ll; const ll INF=1LL<<60; typedef pair<ll,ll> P; typedef pair<int,P> PP; const ll MOD=1e9+7; int main(){ int N; cin>>N; vector<ll> A(N); const int MAXA=1000000; vector<ll> cnt(MAXA+10); ll maxA=0; for(int i=0;i<N;i++){ cin>>A[i]; maxA=max(maxA,A[i]); cnt[A[i]]++; } vector<ll> sum(maxA+1); for(int g=1;g<=maxA;g++){ for(int j=g;j<=maxA;j+=g){ sum[g]+=cnt[j];//jはgの倍数 } } map<ll,ll> ansg; for(int g=1;g<=maxA;g++){ //sumが同じならできるだけ大きいgがいい //ansg[sum[g]]=max(ansg[sum[g]],1LL*g); ansg[sum[g]]=g; } vector<pair<ll,ll>> t;//[数,その値] for(auto [num,g]:ansg){ t.emplace_back(num,g); } //t.emplace_back(make_pair(0LL,1LL<<30));//番兵 t.emplace_back(make_pair(1LL<<60,1LL)); //numが小さい順にソート sort(t.begin(),t.end()); /* for(int j=0;j<=maxA;j++){ cout<<"sum["<<j<<"]="<<sum[j]<<endl; } */ for(int K=0;K<N;K++){ ll ans=0; //cout<<"N-K="<<N-K<<endl; ll c=N-K; //個数がc以上で考えた際に最大のg auto it=lower_bound(t.begin(),t.end(),make_pair(c,0LL)); //it--; ans=it->second; cout<<ans<<endl; } }