結果
問題 |
No.390 最長の数列
|
ユーザー |
![]() |
提出日時 | 2016-07-20 20:40:24 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 1,319 ms / 5,000 ms |
コード長 | 950 bytes |
コンパイル時間 | 1,001 ms |
コンパイル使用メモリ | 82,724 KB |
実行使用メモリ | 35,448 KB |
最終ジャッジ日時 | 2024-10-02 11:00:26 |
合計ジャッジ時間 | 5,937 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 15 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:14:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 14 | scanf("%d",&n); | ~~~~~^~~~~~~~~ main.cpp:17:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 17 | scanf("%d",&e); | ~~~~~^~~~~~~~~
ソースコード
#include <iostream> #include <stdio.h> #include <set> #include <vector> #include <algorithm> #include <map> using namespace std; std::vector<int> vec,con[100000],cs; std::map<int,int> ms; int main() { // your code goes here std::set<int> sets; int n; scanf("%d",&n); for(int i=0;i<n;i++){ int e; scanf("%d",&e); vec.push_back(e); sets.insert(e); cs.push_back(0); } std::sort(vec.begin(),vec.end()); for(int i=0;i<n;i++){ ms[vec[i]]=i; } for(int i=0;i<n;i++){ int p=vec[i]; for(int j=1;j*j<=p;j++){ if(p%j==0){ int k=p/j; if((sets.find(j)!=sets.end())&&(j!=p)){ con[ms[j]].push_back(i); } if(k==j)continue; if((sets.find(k)!=sets.end())&&(k!=p)){ con[ms[k]].push_back(i); } } } } int ans=0; for(int i=0;i<n;i++){ for(int j=0;j<con[i].size();j++){ int p=con[i][j]; cs[p]=std::max(cs[p],cs[i]+1); ans=std::max(ans,cs[p]); } } printf("%d\n",ans+1); return 0; }