結果
問題 | No.1730 GCD on Blackboard in yukicoder |
ユーザー |
|
提出日時 | 2023-07-17 19:21:35 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 326 ms / 2,000 ms |
コード長 | 1,820 bytes |
コンパイル時間 | 895 ms |
コンパイル使用メモリ | 107,472 KB |
最終ジャッジ日時 | 2025-02-15 15:28:14 |
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 24 |
ソースコード
#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の倍数 } } vector<ll> ans(N+1,0); for(int i=1;i<=MAXA;i++){ ans[max(N-sum[i],0LL)]=i; // ans[全体N - gの倍数の個数]=i } for(int i=1;i<=N;i++){ ans[i]=max(ans[i],ans[i-1]); } for(int i=0;i<N;i++){ cout<<ans[i]<<endl; } /* 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 K=0;K<N;K++){ ll ans=0; //cout<<"N-K="<<N-K<<endl; ll c=N-K; //個数がc以上で考えた際に最大のg auto it=upper_bound(t.begin(),t.end(),make_pair(c,1LL<<30)); it--; ans=it->second; cout<<ans<<endl; } */ }