結果

問題 No.390 最長の数列
ユーザー rapurasurapurasu
提出日時 2016-07-13 16:05:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 502 ms / 5,000 ms
コード長 904 bytes
コンパイル時間 1,861 ms
コンパイル使用メモリ 169,368 KB
実行使用メモリ 8,824 KB
最終ジャッジ日時 2024-04-10 09:07:39
合計ジャッジ時間 5,068 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
8,464 KB
testcase_01 AC 4 ms
8,520 KB
testcase_02 AC 4 ms
8,480 KB
testcase_03 AC 4 ms
8,292 KB
testcase_04 AC 5 ms
8,412 KB
testcase_05 AC 502 ms
8,764 KB
testcase_06 AC 334 ms
8,696 KB
testcase_07 AC 5 ms
8,384 KB
testcase_08 AC 4 ms
8,356 KB
testcase_09 AC 4 ms
8,376 KB
testcase_10 AC 376 ms
8,824 KB
testcase_11 AC 373 ms
8,732 KB
testcase_12 AC 372 ms
8,680 KB
testcase_13 AC 262 ms
8,728 KB
testcase_14 AC 150 ms
8,700 KB
testcase_15 AC 4 ms
8,392 KB
testcase_16 AC 4 ms
8,472 KB
testcase_17 AC 21 ms
8,452 KB
testcase_18 AC 30 ms
8,360 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

 #include<bits/stdc++.h>
 using namespace std;
#define INF 1000000000
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)

vector<int> A;
int dp[1000001];
bool used[1000001];
int main(){
    long long int N;
    cin>>N;
    REP(i,1000001){
        used[i]=false;
        dp[i]=0;
    }
    REP(i,N){
        int a;
        cin>>a;
        A.push_back(a);
        used[a]=true;
        dp[a]=1;
    }
    sort(A.begin(),A.end());

    for(int i=0;i<N;i++){
        for(int j=1;j<=sqrt(A[i]);j++){
            if(A[i]%j==0){
                int a=A[i]/j;
                if((used[j]==true)&&j!=A[i]){
                   dp[A[i]]=max(dp[A[i]],dp[j]+1);
                }
                if((used[a]==true)&&a!=A[i]){
                   dp[A[i]]=max(dp[A[i]],dp[a]+1);
                }
            }
        }
    }
    int m=0;
    for(int i=0;i<N;i++){
        m=max(dp[A[i]],m);
    }
    cout<<m<<endl;
}
0