結果

問題 No.979 Longest Divisor Sequence
ユーザー 👑 rin204rin204
提出日時 2022-03-24 17:09:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 645 bytes
コンパイル時間 2,423 ms
コンパイル使用メモリ 193,800 KB
実行使用メモリ 6,940 KB
最終ジャッジ日時 2024-04-21 02:47:07
合計ジャッジ時間 3,105 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const int N = 300300;
int dp[N];
int main(void){
    int n;
    cin >> n;
    for(int i = 1; i < N; i++) dp[i] = 0;
    
    int a, ma, ans = 0;
    for(int i = 0; i < n; i++){
        cin >> a;
        if(a == 1) ma = 1;
        else if(dp[1] + 1 > dp[a]) ma = dp[1] + 1;
        else ma = dp[a];
        
        for(int i = 2; i * i <= a; i++){
            if(a % i == 0){
                if(dp[i] + 1 > ma) ma = dp[i + 1];
                if(dp[a / i] + 1 > ma) ma = dp[a / i] + 1;
            }
        }
        dp[a] = ma;
        if(ma > ans) ans = ma;
    }
    cout << ans << "\n";
    
}
0