結果

問題 No.979 Longest Divisor Sequence
ユーザー veqccveqcc
提出日時 2020-01-31 22:41:37
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 543 ms / 2,000 ms
コード長 1,186 bytes
コンパイル時間 1,020 ms
コンパイル使用メモリ 109,104 KB
実行使用メモリ 5,592 KB
最終ジャッジ日時 2023-10-17 11:14:11
合計ジャッジ時間 2,479 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,536 KB
testcase_01 AC 3 ms
4,536 KB
testcase_02 AC 3 ms
4,536 KB
testcase_03 AC 3 ms
4,536 KB
testcase_04 AC 2 ms
4,536 KB
testcase_05 AC 3 ms
4,536 KB
testcase_06 AC 3 ms
4,536 KB
testcase_07 AC 3 ms
4,536 KB
testcase_08 AC 3 ms
4,536 KB
testcase_09 AC 2 ms
4,536 KB
testcase_10 AC 9 ms
4,536 KB
testcase_11 AC 8 ms
4,536 KB
testcase_12 AC 8 ms
4,536 KB
testcase_13 AC 21 ms
5,592 KB
testcase_14 AC 543 ms
5,592 KB
testcase_15 AC 181 ms
4,800 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

int main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin >> n;

    vector <int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];

    vector <int> dp(300005);
    for (int i = 0; i < n; i++) {
        if (a[i] == 1) {
            dp[1] = 1;
            continue;
        }
        
        auto div = divisor(a[i]);
        for (int val : div) {
            if (val == a[i]) continue;
            dp[a[i]] = max(dp[a[i]], dp[val] + 1);
        }
    }

    int ans = 1;
    for (int i = 0; i < n; i++) {
        ans = max(ans, dp[a[i]]);
    }

    cout << ans << "\n";
    return 0;
}
0