結果

問題 No.979 Longest Divisor Sequence
ユーザー otamay6otamay6
提出日時 2020-01-31 22:07:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 498 ms / 2,000 ms
コード長 725 bytes
コンパイル時間 1,598 ms
コンパイル使用メモリ 169,628 KB
実行使用メモリ 5,684 KB
最終ジャッジ日時 2023-10-17 09:56:46
合計ジャッジ時間 3,052 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 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,628 KB
testcase_11 AC 8 ms
4,628 KB
testcase_12 AC 8 ms
4,628 KB
testcase_13 AC 48 ms
4,364 KB
testcase_14 AC 498 ms
5,684 KB
testcase_15 AC 167 ms
4,892 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

int main(){
    int N;cin>>N;
    vector<int> A(N);
    REP(i, N) cin >> A[i];
    int MAX=*max_element(All(A));
    vector<int> dp(MAX+1);
    REP(i,N){
        if(A[i]>1) dp[A[i]]=max(dp[A[i]],dp[1]+1);
        else dp[1]=1;
        for(int j=2;j*j<=A[i];++j){
            if(A[i]%j==0){
                dp[A[i]]=max({dp[A[i]],dp[j]+1,dp[A[i]/j]+1});
            }
        }
    }
    // REP(i,MAX+1) cout<<i<<" "<<dp[i]<<endl;
    cout<<*max_element(All(dp))<<endl;
}
0