結果

問題 No.390 最長の数列
ユーザー treeonetreeone
提出日時 2016-07-14 08:46:43
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 70 ms / 5,000 ms
コード長 675 bytes
コンパイル時間 1,320 ms
コンパイル使用メモリ 165,200 KB
実行使用メモリ 11,864 KB
最終ジャッジ日時 2024-04-10 09:10:19
合計ジャッジ時間 2,514 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
10,908 KB
testcase_01 AC 6 ms
11,028 KB
testcase_02 AC 5 ms
11,004 KB
testcase_03 AC 5 ms
11,056 KB
testcase_04 AC 5 ms
11,052 KB
testcase_05 AC 45 ms
11,684 KB
testcase_06 AC 70 ms
11,844 KB
testcase_07 AC 6 ms
10,944 KB
testcase_08 AC 6 ms
11,020 KB
testcase_09 AC 6 ms
10,844 KB
testcase_10 AC 49 ms
11,796 KB
testcase_11 AC 50 ms
11,852 KB
testcase_12 AC 49 ms
11,864 KB
testcase_13 AC 37 ms
11,512 KB
testcase_14 AC 44 ms
11,708 KB
testcase_15 AC 6 ms
10,988 KB
testcase_16 AC 5 ms
10,856 KB
testcase_17 AC 7 ms
10,876 KB
testcase_18 AC 9 ms
10,968 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repp(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;
typedef pair<int, int> P;

signed main(){
    int n;
    cin >> n;
    vector<int> x(n);
    rep(i, 0, n) cin >> x[i];
    sort(all(x));
    vector<int> dp(1000001);
    int MAX = x[n - 1];

    for(auto i:x){
        dp[i] = 1;
    }

    for(auto i: x){
        for(int j = 2 * i; j <= MAX; j += i){
            if(dp[j] == 0) continue;
            dp[j] = max(dp[j], dp[i] + 1);
        }
    }

    cout << *max_element(all(dp)) << endl;
}
0