結果

問題 No.979 Longest Divisor Sequence
ユーザー merom686merom686
提出日時 2020-02-01 00:07:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 450 ms / 2,000 ms
コード長 867 bytes
コンパイル時間 678 ms
コンパイル使用メモリ 76,664 KB
実行使用メモリ 5,532 KB
最終ジャッジ日時 2023-10-17 14:00:38
合計ジャッジ時間 2,241 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    int n;
    cin >> n;

    vector<int> dp(n), b((int)3e+5 + 1, -1);
    int r = 0;

    for (int i = 0; i < n; i++) {
        int t;
        cin >> t;
        int s = 0;
        if (t > 1) {
            if (b[1] >= 0) s = max(s, dp[b[1]]);
            for (int k = 2; k * k <= t; k++) {
                if (t % k == 0) {
                    int l = t / k;
                    if (b[k] >= 0) s = max(s, dp[b[k]]);
                    if (b[l] >= 0) s = max(s, dp[b[l]]);
                }
            }
        }
        b[t] = i;
        dp[i] = s + 1;
        r = max(r, dp[i]);
    }

    cout << r << endl;

    return 0;
}
0