結果

問題 No.979 Longest Divisor Sequence
ユーザー wait_sushiwait_sushi
提出日時 2020-01-31 22:50:37
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,302 ms / 2,000 ms
コード長 1,574 bytes
コンパイル時間 1,564 ms
コンパイル使用メモリ 170,936 KB
実行使用メモリ 11,896 KB
最終ジャッジ日時 2023-10-17 11:31:06
合計ジャッジ時間 4,240 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,228 KB
testcase_01 AC 4 ms
7,228 KB
testcase_02 AC 4 ms
7,228 KB
testcase_03 AC 4 ms
7,228 KB
testcase_04 AC 4 ms
7,228 KB
testcase_05 AC 4 ms
7,228 KB
testcase_06 AC 4 ms
7,228 KB
testcase_07 AC 4 ms
7,228 KB
testcase_08 AC 4 ms
7,228 KB
testcase_09 AC 4 ms
7,228 KB
testcase_10 AC 18 ms
7,440 KB
testcase_11 AC 18 ms
7,440 KB
testcase_12 AC 17 ms
7,440 KB
testcase_13 AC 51 ms
11,896 KB
testcase_14 AC 1,302 ms
11,896 KB
testcase_15 AC 432 ms
8,292 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
#define inputv(v, n)                                                           \
    vl v;                                                                      \
    rep(i, n) {                                                                \
        ll x;                                                                  \
        cin >> x;                                                              \
        v.push_back(x);                                                        \
    }
bool chmin(ll& a, ll b) { if (b < a) { a = b; return 1; } return 0; }
bool chmax(ll& a, ll b) { if (b > a) { a = b; return 1; } return 0; }
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
vl V;
int main() {
    cin >> n;
    vl dp(MAX_N, 0);
    inputv(A, n);

    rep(i, n) {
        if (i == 0)dp[A[i]] = 1;
        else if(A[i]==1)dp[1]=1;
        else {
            for (ll j = 1; j * j <= A[i]; j++) {
                if (A[i] % j == 0) {
                    if (j * j == A[i])chmax(dp[A[i]],dp[j]+1);
                    else {
                        chmax(dp[A[i]], dp[j]+1);
                        if(j!=1)chmax(dp[A[i]], dp[A[i]/j]+1);
                    }
                }
            }
        }
    }

    cout << dp[max_element(all(dp)) - dp.begin()] << endl;

}
0