結果
問題 |
No.1730 GCD on Blackboard in yukicoder
|
ユーザー |
|
提出日時 | 2022-01-15 17:31:22 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 850 ms / 2,000 ms |
コード長 | 1,038 bytes |
コンパイル時間 | 873 ms |
コンパイル使用メモリ | 69,632 KB |
最終ジャッジ日時 | 2025-01-27 12:36:17 |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 24 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:34:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 34 | scanf("%d",&n); | ~~~~~^~~~~~~~~ main.cpp:36:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 36 | scanf("%d",&u); | ~~~~~^~~~~~~~~
ソースコード
#include <stdio.h> #include <algorithm> #include <numeric> #include <unordered_map> #include <vector> #define qaq inline const int sz=1e6+19; int n,arr[sz]; std::unordered_map<int,int> cnts; std::vector<int> solve(){ std::vector<int> divCnt(1e6+1,0),divisors; for(auto [ele,ct]:cnts){ divisors.clear(); for(int cx=1;cx*cx<=ele;++cx){ if(ele%cx==0){ divisors.push_back(cx); if(cx*cx!=ele) divisors.push_back(ele/cx); } } for(auto cx:divisors) divCnt[cx]+=ct; } std::vector<int> ans(n,0); for(int cx=1;cx<=1e6;++cx){ if(divCnt[cx]!=0) ans[n-divCnt[cx]]=std::max(ans[n-divCnt[cx]],cx); } for(int cx=1;cx<n;++cx) ans[cx]=std::max(ans[cx],ans[cx-1]); return ans; } int main(){ scanf("%d",&n); for(int cx=0,u;cx<n;++cx){ scanf("%d",&u); cnts[u]++; } auto ans=solve(); for(auto cx:ans) printf("%d\n",cx); return 0; }