結果

問題 No.979 Longest Divisor Sequence
ユーザー kyort0nkyort0n
提出日時 2020-01-31 21:45:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 545 ms / 2,000 ms
コード長 1,297 bytes
コンパイル時間 1,632 ms
コンパイル使用メモリ 170,208 KB
実行使用メモリ 8,368 KB
最終ジャッジ日時 2023-10-17 09:07:41
合計ジャッジ時間 3,184 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
8,360 KB
testcase_01 AC 4 ms
8,360 KB
testcase_02 AC 3 ms
8,360 KB
testcase_03 AC 4 ms
8,360 KB
testcase_04 AC 3 ms
8,360 KB
testcase_05 AC 3 ms
8,360 KB
testcase_06 AC 4 ms
8,360 KB
testcase_07 AC 4 ms
8,360 KB
testcase_08 AC 3 ms
8,360 KB
testcase_09 AC 3 ms
8,360 KB
testcase_10 AC 9 ms
8,368 KB
testcase_11 AC 9 ms
8,368 KB
testcase_12 AC 9 ms
8,368 KB
testcase_13 AC 30 ms
8,304 KB
testcase_14 AC 545 ms
8,368 KB
testcase_15 AC 184 ms
8,368 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[300001];

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];
    for(int i = 1; i <= 3e5; 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