結果

問題 No.979 Longest Divisor Sequence
ユーザー betrue12betrue12
提出日時 2020-01-31 21:42:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 457 ms / 2,000 ms
コード長 465 bytes
コンパイル時間 2,109 ms
コンパイル使用メモリ 203,564 KB
実行使用メモリ 5,684 KB
最終ジャッジ日時 2023-10-17 09:04:52
合計ジャッジ時間 3,553 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,364 KB
testcase_01 AC 4 ms
4,364 KB
testcase_02 AC 3 ms
4,364 KB
testcase_03 AC 3 ms
4,364 KB
testcase_04 AC 3 ms
4,364 KB
testcase_05 AC 3 ms
4,364 KB
testcase_06 AC 3 ms
4,364 KB
testcase_07 AC 3 ms
4,364 KB
testcase_08 AC 3 ms
4,364 KB
testcase_09 AC 3 ms
4,364 KB
testcase_10 AC 8 ms
4,628 KB
testcase_11 AC 8 ms
4,628 KB
testcase_12 AC 8 ms
4,628 KB
testcase_13 AC 50 ms
5,684 KB
testcase_14 AC 457 ms
5,684 KB
testcase_15 AC 154 ms
4,892 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

void chmax(int& a, int b){
    a = max(a, b);
}

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++) cin >> A[i];
    vector<int> dp(300001);
    for(int a : A){
        dp[a] = 1;
        for(int d=1; d*d<=a; d++) if(a%d == 0){
            for(int b : {d, a/d}) if(b < a) chmax(dp[a], dp[b]+1);
        }
    }
    cout << *max_element(dp.begin(), dp.end()) << endl;
    return 0;
}
0