結果

問題 No.390 最長の数列
ユーザー hogeover30hogeover30
提出日時 2016-08-24 03:30:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 357 ms / 5,000 ms
コード長 631 bytes
コンパイル時間 760 ms
コンパイル使用メモリ 76,568 KB
実行使用メモリ 11,420 KB
最終ジャッジ日時 2024-04-10 10:05:46
合計ジャッジ時間 3,207 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
11,124 KB
testcase_01 AC 6 ms
11,040 KB
testcase_02 AC 6 ms
11,200 KB
testcase_03 AC 6 ms
11,152 KB
testcase_04 AC 6 ms
11,016 KB
testcase_05 AC 357 ms
11,416 KB
testcase_06 AC 233 ms
11,380 KB
testcase_07 AC 6 ms
10,972 KB
testcase_08 AC 6 ms
11,116 KB
testcase_09 AC 6 ms
11,052 KB
testcase_10 AC 252 ms
11,304 KB
testcase_11 AC 262 ms
11,416 KB
testcase_12 AC 270 ms
11,392 KB
testcase_13 AC 183 ms
11,336 KB
testcase_14 AC 102 ms
11,420 KB
testcase_15 AC 7 ms
10,904 KB
testcase_16 AC 7 ms
10,968 KB
testcase_17 AC 18 ms
11,196 KB
testcase_18 AC 25 ms
10,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0