結果

問題 No.979 Longest Divisor Sequence
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2020-02-01 23:07:35
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 607 ms / 2,000 ms
コード長 841 bytes
コンパイル時間 1,403 ms
コンパイル使用メモリ 162,848 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 00:26:06
合計ジャッジ時間 3,116 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

// enum_div 約数列挙O(√N)
// 順番はバラバラ
template<typename T>
vector<T> enum_div(T n) {
    vector<T> ret;
    for (T i = 1; i * i <= n; ++i)
    {
        if (n % i == 0)
        {
            ret.push_back(i);
            if (i * i != n)
            {
                ret.push_back(n / i);
            }
        }
    }
    return ret;
}

int main() {
    int n; cin >> n;
    vector<int> v(3 * 100000 + 1, 0);
    int ans = 0;
    for (int i = 0; i < n; i++) {
        int a; cin >> a;
        if (a == 1) v[1] = 1;
        else {
            for (int b : enum_div(a)) {
                if (a == b) continue;
                v[a] = max(v[a], v[b] + 1);
            }
        }
        ans = max(ans, v[a]);
    }
    cout << ans << endl;
    return 0;
}
0