結果

問題 No.979 Longest Divisor Sequence
ユーザー trineutrontrineutron
提出日時 2020-02-08 17:44:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 621 ms / 2,000 ms
コード長 721 bytes
コンパイル時間 2,205 ms
コンパイル使用メモリ 207,144 KB
実行使用メモリ 35,872 KB
最終ジャッジ日時 2023-10-26 01:11:28
合計ジャッジ時間 11,685 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 489 ms
34,620 KB
testcase_01 AC 500 ms
34,620 KB
testcase_02 AC 492 ms
34,620 KB
testcase_03 AC 490 ms
34,620 KB
testcase_04 AC 488 ms
34,620 KB
testcase_05 AC 496 ms
34,620 KB
testcase_06 AC 493 ms
34,620 KB
testcase_07 AC 492 ms
34,620 KB
testcase_08 AC 489 ms
34,620 KB
testcase_09 AC 494 ms
34,620 KB
testcase_10 AC 511 ms
34,620 KB
testcase_11 AC 516 ms
34,620 KB
testcase_12 AC 495 ms
34,620 KB
testcase_13 AC 537 ms
35,872 KB
testcase_14 AC 621 ms
35,872 KB
testcase_15 AC 541 ms
34,884 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a.at(i);
    vector<vector<int>> d(300001);
    for (int i = 1; i <= 300000; i++) {
        for (int j = 1; j * j <= i; j++) {
            if (i % j) continue;
            d.at(i).push_back(j);
            d.at(i).push_back(i / j);
        }
    }
    vector<int> dp(300001);
    for (int i = 0; i < n; i++) {
        dp.at(a.at(i)) = max(dp.at(a.at(i)), 1);
        for (int x : d.at(a.at(i))) {
            if (x == a.at(i)) continue;
            dp.at(a.at(i)) = max(dp.at(a.at(i)), dp.at(x) + 1);
        }
    }
    cout << *max_element(dp.begin(), dp.end()) << endl;
}
0