結果

問題 No.390 最長の数列
ユーザー Ai3ShotaAi3Shota
提出日時 2018-06-29 17:14:33
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 67 ms / 5,000 ms
コード長 571 bytes
コンパイル時間 1,596 ms
コンパイル使用メモリ 149,532 KB
実行使用メモリ 7,832 KB
最終ジャッジ日時 2023-09-13 15:13:48
合計ジャッジ時間 2,537 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,876 KB
testcase_01 AC 4 ms
6,664 KB
testcase_02 AC 4 ms
6,856 KB
testcase_03 AC 4 ms
6,856 KB
testcase_04 AC 4 ms
6,820 KB
testcase_05 AC 42 ms
7,532 KB
testcase_06 AC 67 ms
7,636 KB
testcase_07 AC 3 ms
6,808 KB
testcase_08 AC 5 ms
6,660 KB
testcase_09 AC 5 ms
6,708 KB
testcase_10 AC 48 ms
7,676 KB
testcase_11 AC 49 ms
7,668 KB
testcase_12 AC 48 ms
7,664 KB
testcase_13 AC 33 ms
7,532 KB
testcase_14 AC 39 ms
7,832 KB
testcase_15 AC 4 ms
6,712 KB
testcase_16 AC 5 ms
6,956 KB
testcase_17 AC 7 ms
6,780 KB
testcase_18 AC 8 ms
6,960 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

int N;
vector<int> x;
vector<int> dp(1000001, 0);

int main(void){
    
    cin >> N;
    for(int i = 0; i < N; ++i){
        int n; cin >> n;
        x.push_back(n);
        dp[x[i]] = 1;
    }
    sort(x.begin(), x.end());
    
    for(auto i : x){
        for(int j = i + i; j <= x[N - 1]; j += i){
            if(dp[j]) dp[j] = max(dp[j], dp[i] + 1);
        }
    }
    
    int ans = 0;
    for(int i = 0; i <= x[N - 1]; ++i) ans = max(ans, dp[i]);
    cout << ans << endl;
    
    return 0;
}

0