結果

問題 No.390 最長の数列
ユーザー RubikunRubikun
提出日時 2019-08-04 18:08:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 346 ms / 5,000 ms
コード長 653 bytes
コンパイル時間 1,514 ms
コンパイル使用メモリ 169,648 KB
実行使用メモリ 7,552 KB
最終ジャッジ日時 2023-09-22 21:39:03
合計ジャッジ時間 4,174 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,844 KB
testcase_01 AC 4 ms
6,920 KB
testcase_02 AC 4 ms
6,844 KB
testcase_03 AC 4 ms
6,924 KB
testcase_04 AC 3 ms
6,936 KB
testcase_05 AC 346 ms
7,208 KB
testcase_06 AC 236 ms
7,552 KB
testcase_07 AC 4 ms
6,896 KB
testcase_08 AC 4 ms
7,028 KB
testcase_09 AC 5 ms
6,904 KB
testcase_10 AC 252 ms
7,168 KB
testcase_11 AC 253 ms
7,208 KB
testcase_12 AC 252 ms
7,192 KB
testcase_13 AC 180 ms
7,168 KB
testcase_14 AC 110 ms
7,552 KB
testcase_15 AC 4 ms
6,896 KB
testcase_16 AC 5 ms
6,896 KB
testcase_17 AC 15 ms
6,964 KB
testcase_18 AC 23 ms
6,892 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100003,INF=1<<30;

int main(){

    int N;cin>>N;
    vector<int> A(N);
    vector<int> B(1000001,0);
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    
    sort(all(A));
    
    for(int i=0;i<N;i++){
        int maxi=B[1];
        for(int j=2;j*j<=A[i];j++){
            if(A[i]%j==0){
                maxi=max({maxi,B[j],B[A[i]/j]});
            }
        }
        B[A[i]]=maxi+1;
    }
    
    int ans=0;
    
    for(int i=0;i<1000001;i++){
        ans=max(ans,B[i]);
    }
    
    cout<<ans<<endl;
    
}
0