結果

問題 No.979 Longest Divisor Sequence
ユーザー veqccveqcc
提出日時 2020-01-31 22:35:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,086 bytes
コンパイル時間 1,054 ms
コンパイル使用メモリ 109,904 KB
実行使用メモリ 5,592 KB
最終ジャッジ日時 2023-10-17 10:52:53
合計ジャッジ時間 2,484 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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(1, 1);
    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(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, 1);
    for (int i = 0; i < n; i++) {
        if (a[i] == 1) continue;
        auto div = divisor(a[i]);
        for (int val : div) {
            dp[a[i]] = max(dp[a[i]], dp[val] + 1);
        }
    }

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

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