結果

問題 No.979 Longest Divisor Sequence
ユーザー roarisroaris
提出日時 2020-07-25 23:45:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,230 ms / 2,000 ms
コード長 673 bytes
コンパイル時間 1,910 ms
コンパイル使用メモリ 198,368 KB
実行使用メモリ 8,044 KB
最終ジャッジ日時 2023-09-10 02:16:05
合計ジャッジ時間 4,482 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,408 KB
testcase_01 AC 4 ms
5,380 KB
testcase_02 AC 4 ms
5,536 KB
testcase_03 AC 3 ms
5,504 KB
testcase_04 AC 4 ms
5,412 KB
testcase_05 AC 4 ms
5,464 KB
testcase_06 AC 3 ms
5,372 KB
testcase_07 AC 4 ms
5,648 KB
testcase_08 AC 4 ms
5,644 KB
testcase_09 AC 3 ms
5,464 KB
testcase_10 AC 17 ms
7,416 KB
testcase_11 AC 17 ms
7,536 KB
testcase_12 AC 17 ms
7,452 KB
testcase_13 AC 21 ms
5,984 KB
testcase_14 AC 1,230 ms
8,044 KB
testcase_15 AC 410 ms
7,652 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<n; i++)
#define pb push_back
#define int long long

int N;
int A[300010];
int dp[300010];
 
signed main() {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> N;
    rep(i, N) cin >> A[i];
    for (auto& Ai:A) {
        dp[Ai] = 1;
        if (Ai==1) continue;
        int i = 1;
        while (i*i<=Ai) {
            if (Ai%i==0) {
                if (i==1) dp[Ai] = max(dp[Ai], dp[i]+1);
                else dp[Ai] = max({dp[Ai], dp[i]+1, dp[Ai/i]+1});
            }
            i++;
        }
    }
    int ans = 0;
    rep(i, 300010) ans = max(ans, dp[i]);
    cout << ans << endl;
}
0