結果

問題 No.390 最長の数列
ユーザー rogi52rogi52
提出日時 2022-08-13 15:42:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 47 ms / 5,000 ms
コード長 527 bytes
コンパイル時間 2,502 ms
コンパイル使用メモリ 203,320 KB
実行使用メモリ 7,104 KB
最終ジャッジ日時 2023-10-24 23:54:29
合計ジャッジ時間 3,561 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
7,104 KB
testcase_01 AC 6 ms
7,104 KB
testcase_02 AC 7 ms
7,104 KB
testcase_03 AC 7 ms
7,104 KB
testcase_04 AC 8 ms
7,104 KB
testcase_05 AC 14 ms
7,104 KB
testcase_06 AC 47 ms
7,104 KB
testcase_07 AC 6 ms
7,104 KB
testcase_08 AC 5 ms
7,104 KB
testcase_09 AC 6 ms
7,104 KB
testcase_10 AC 22 ms
7,104 KB
testcase_11 AC 22 ms
7,104 KB
testcase_12 AC 21 ms
7,104 KB
testcase_13 AC 18 ms
7,104 KB
testcase_14 AC 38 ms
7,104 KB
testcase_15 AC 5 ms
7,104 KB
testcase_16 AC 4 ms
7,104 KB
testcase_17 AC 5 ms
7,104 KB
testcase_18 AC 5 ms
7,104 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int N; cin >> N;
    int MAX_X = 1000000;
    vector<int> dp(MAX_X + 1, 0);
    rep(i,N) {
        int x; cin >> x;
        dp[x] = 1;
    }

    for(int i = MAX_X; i >= 1; i--) if(dp[i])
        for(int k = i + i; k <= MAX_X; k += i) if(dp[k])
            dp[i] = max(dp[i], dp[k] + 1);

    cout << *max_element(dp.begin(), dp.end()) << endl;
}
0