結果
問題 | No.1730 GCD on Blackboard in yukicoder |
ユーザー |
![]() |
提出日時 | 2021-11-05 21:39:02 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,326 ms / 2,000 ms |
コード長 | 1,434 bytes |
コンパイル時間 | 2,517 ms |
コンパイル使用メモリ | 198,784 KB |
最終ジャッジ日時 | 2025-01-25 12:04:16 |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 24 |
ソースコード
#include <bits/stdc++.h>#define rep(i,n) for (int i = 0; i < int(n); ++i)#define repp(i,n,m) for (int i = m; i < int(n); ++i)using namespace std;using P = pair<int, int>;template<class T>istream &operator>>(istream &is,vector<T> &v){for(auto &e:v)is>>e;return is;}template<class T>ostream &operator<<(ostream &os,const vector<T> &v){if(v.size()==0){os<<endl;}else{rep(i,v.size())os<<v[i]<<(i+1==v.size()?"\n":" ");}return os;}template<class T>istream &operator>>(istream &is,vector<vector<T>> &v){for(auto &e:v)is>>e;return is;}template<class T>ostream &operator<<(ostream &os,const vector<vector<T>> &v){if(v.size()==0){os<<endl;}else{for(auto &e:v)os<<e;}return os;}template<typename T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}template<typename T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}int main(){int n; cin >> n;vector<int> ar(n); cin >> ar;vector<int> cnt(1000001,0);rep(i,n){for (int d = 1; d * d <= ar[i]; d++){if (ar[i] % d == 0){cnt[d]++;if (d * d != ar[i]) cnt[ar[i] / d]++;}}}priority_queue<P> pque;repp(i,1000001,1) pque.push(P(cnt[i],i));int ans = 0;rep(i,n){while (!pque.empty() && pque.top().first >= n - i){chmax(ans,pque.top().second);pque.pop();}cout << ans << endl;}}