結果

問題 No.390 最長の数列
ユーザー Manuel1024Manuel1024
提出日時 2022-04-06 03:45:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 60 ms / 5,000 ms
コード長 511 bytes
コンパイル時間 580 ms
コンパイル使用メモリ 71,392 KB
実行使用メモリ 7,696 KB
最終ジャッジ日時 2023-08-18 10:04:23
合計ジャッジ時間 2,538 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
6,924 KB
testcase_01 AC 31 ms
6,884 KB
testcase_02 AC 32 ms
6,988 KB
testcase_03 AC 31 ms
6,976 KB
testcase_04 AC 32 ms
6,992 KB
testcase_05 AC 60 ms
7,460 KB
testcase_06 AC 59 ms
7,088 KB
testcase_07 AC 31 ms
6,824 KB
testcase_08 AC 32 ms
6,980 KB
testcase_09 AC 31 ms
6,996 KB
testcase_10 AC 59 ms
7,696 KB
testcase_11 AC 60 ms
7,520 KB
testcase_12 AC 60 ms
7,308 KB
testcase_13 AC 53 ms
7,084 KB
testcase_14 AC 57 ms
7,512 KB
testcase_15 AC 32 ms
6,988 KB
testcase_16 AC 31 ms
6,928 KB
testcase_17 AC 32 ms
6,988 KB
testcase_18 AC 33 ms
6,992 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    int n; cin >> n;
    vector<int> a(n);
    for(auto &it: a) cin >> it;

    vector<int> dp(1000010, 0);
    for(auto &it: a) dp[it] = 1;
    for(int i = 1000000; i > 0; i--){
        int mx = 0;
        for(int j = i*2; j < dp.size(); j += i){
            mx = max(mx, dp[j]);
        }
        dp[i] += mx;
    }

    int ans = 0;
    for(auto &it: dp) ans = max(ans, it);
    cout << ans << endl;
    return 0;
}
0