結果

問題 No.979 Longest Divisor Sequence
ユーザー hanbei_dayohanbei_dayo
提出日時 2020-02-01 16:07:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 455 ms / 2,000 ms
コード長 920 bytes
コンパイル時間 749 ms
コンパイル使用メモリ 84,320 KB
実行使用メモリ 5,696 KB
最終ジャッジ日時 2023-10-19 00:06:10
合計ジャッジ時間 2,109 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 3 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 3 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,876 KB
testcase_11 AC 8 ms
4,876 KB
testcase_12 AC 8 ms
4,872 KB
testcase_13 AC 48 ms
4,652 KB
testcase_14 AC 455 ms
5,696 KB
testcase_15 AC 155 ms
4,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<math.h>
using namespace std;
#define mod (1000000000+7)
#define N (10007)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;

int dp[300010];

int main(){
    int n;
    cin>>n;
    vector<int>a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++){
        for(int j=1;j*j<=a[i];j++){
            if(a[i]==1){
                dp[a[i]]=1;
                continue;
            }
            if(j==1)dp[a[i]]=max(dp[a[i]],dp[j]+1);
            else{
                if(a[i]%j==0){
                    dp[a[i]]=max(dp[a[i]],dp[j]+1);
                    dp[a[i]]=max(dp[a[i]],dp[a[i]/j]+1);
                }
            }
        }
    }
    int ans = 0;
    for(int i=0;i<300010;i++)ans=max(ans,dp[i]);
    cout<<ans<<endl;
    return 0;
}
0