結果

問題 No.390 最長の数列
ユーザー kyort0nkyort0n
提出日時 2020-01-31 23:56:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 415 ms / 5,000 ms
コード長 1,317 bytes
コンパイル時間 1,726 ms
コンパイル使用メモリ 172,420 KB
実行使用メモリ 12,488 KB
最終ジャッジ日時 2023-10-17 13:55:23
合計ジャッジ時間 4,741 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
12,480 KB
testcase_01 AC 5 ms
12,484 KB
testcase_02 AC 4 ms
12,480 KB
testcase_03 AC 4 ms
12,480 KB
testcase_04 AC 4 ms
12,480 KB
testcase_05 AC 415 ms
12,488 KB
testcase_06 AC 281 ms
12,488 KB
testcase_07 AC 5 ms
12,416 KB
testcase_08 AC 4 ms
12,484 KB
testcase_09 AC 4 ms
12,484 KB
testcase_10 AC 297 ms
12,488 KB
testcase_11 AC 303 ms
12,488 KB
testcase_12 AC 295 ms
12,488 KB
testcase_13 AC 183 ms
12,484 KB
testcase_14 AC 121 ms
12,488 KB
testcase_15 AC 4 ms
12,480 KB
testcase_16 AC 5 ms
12,488 KB
testcase_17 AC 18 ms
12,488 KB
testcase_18 AC 27 ms
12,488 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
ll N;
ll A[300001];
ll dp[1000001];

vector<int> Div(int a) {
    vector<int> ret;
    for(int i = 1; i * i <= a; i++) {
        if(a % i != 0) continue;
        ret.push_back(i);
        if(i * i != a) ret.push_back(a / i);
    }
    return ret;
}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    for(int i = 0; i < N; i++) cin >> A[i];
    sort(A, A + N);
    for(int i = 1; i <= 1e6; i++) dp[i] = 1;
    ll ans = 0;
    for(int i = N - 1; i >= 0; i--) {
        //for(int i = 0; i <= 10; i++) cerr << dp[i] << " ";
        //cerr << endl;
        ll New = dp[A[i]] + 1;
        chmax(ans, dp[A[i]]);
        vector<int> v = Div(A[i]);
        for(auto val : v) {
            if(val == A[i]) continue;
            chmax(dp[val], New);
        }
    }
    cout << ans << endl;
    return 0;
}
0