結果
| 問題 | No.390 最長の数列 | 
| コンテスト | |
| ユーザー |  hogeover30 | 
| 提出日時 | 2016-08-24 03:30:54 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 363 ms / 5,000 ms | 
| コード長 | 631 bytes | 
| コンパイル時間 | 895 ms | 
| コンパイル使用メモリ | 75,604 KB | 
| 実行使用メモリ | 11,452 KB | 
| 最終ジャッジ日時 | 2024-10-02 11:55:52 | 
| 合計ジャッジ時間 | 3,167 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 15 | 
ソースコード
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
    cin.sync_with_stdio(0);
    cin.tie(0);
    int n; cin>>n;
    vector<int> a(n), s(1000001);
    for(int& e: a) {
        cin>>e;
        s[e]++;
    }
    sort(begin(a), end(a));
    vector<int> dp(1000001);
    for(int e: a) {
        for(int i=1; i*i<=e; ++i) {
            int x=-1, y=-1;
            if (e%i==0) {
                if (s[i]) x=dp[i]+1;
                if (s[e/i] and i*i<e) y=dp[e/i]+1;
                dp[e]=max({dp[e], x, y});
            }
        }
    }
    cout<<*max_element(begin(dp), end(dp))<<endl;
}
            
            
            
        