結果

問題 No.979 Longest Divisor Sequence
ユーザー cotton_fn_cotton_fn_
提出日時 2020-01-31 22:47:34
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 534 ms / 2,000 ms
コード長 1,102 bytes
コンパイル時間 1,127 ms
コンパイル使用メモリ 123,660 KB
実行使用メモリ 4,804 KB
最終ジャッジ日時 2023-10-17 11:25:14
合計ジャッジ時間 2,619 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <complex>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T> T iabs(const T& x) { return max(x, -x); }

unsigned char b[300001];
int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
        b[a[i]] = a[i] == 1 ? 1 : b[1] + 1;
        for (int x = 2; x * x <= a[i]; ++x) {
            if (a[i] % x == 0) {
                b[a[i]] = max(b[a[i]], (unsigned char)(b[x] + 1));
                b[a[i]] = max(b[a[i]], (unsigned char)(b[a[i] / x] + 1));
            }
        }
    }
    int ans = 0;
    for (int i = 1; i <= 300000; ++i) {
        ans = max(ans, int(b[i]));
    }
    cout << ans << endl;
    return 0;
}
0