結果

問題 No.979 Longest Divisor Sequence
ユーザー minatominato
提出日時 2020-02-01 16:22:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 572 ms / 2,000 ms
コード長 1,390 bytes
コンパイル時間 2,179 ms
コンパイル使用メモリ 182,052 KB
実行使用メモリ 36,864 KB
最終ジャッジ日時 2023-10-19 00:06:49
合計ジャッジ時間 3,549 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,596 KB
testcase_01 AC 3 ms
4,596 KB
testcase_02 AC 3 ms
4,596 KB
testcase_03 AC 3 ms
4,596 KB
testcase_04 AC 3 ms
4,596 KB
testcase_05 AC 3 ms
4,596 KB
testcase_06 AC 3 ms
4,596 KB
testcase_07 AC 3 ms
4,596 KB
testcase_08 AC 3 ms
4,596 KB
testcase_09 AC 3 ms
4,596 KB
testcase_10 AC 9 ms
4,860 KB
testcase_11 AC 9 ms
4,860 KB
testcase_12 AC 9 ms
4,860 KB
testcase_13 AC 24 ms
13,896 KB
testcase_14 AC 572 ms
36,864 KB
testcase_15 AC 196 ms
15,156 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
//const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
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; }
///////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    vector<int> A(N);
    rep(i,N) cin >> A[i];

    vector<vector<int>> G(N);
    rep(i,N) {
        if (A[i] == 1) continue;
        G[i].emplace_back(1);
        for (int j = 2; j*j <= A[i]; j++) {
            if (A[i]%j==0) {
                G[i].emplace_back(j);
                G[i].emplace_back(A[i]/j);
            }
        }
    }

    vector<int> B(300001),dp(N);
    rep(i,N) {
        if (A[i] == 1) {
            dp[i] = 1;
            B[1] = 1;
            continue;
        }
        for (auto j : G[i]) {
            chmax(dp[i],B[j]+1);
        }
        chmax(B[A[i]],dp[i]);
    }

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