結果

問題 No.979 Longest Divisor Sequence
ユーザー RubikunRubikun
提出日時 2020-01-31 21:51:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 397 ms / 2,000 ms
コード長 828 bytes
コンパイル時間 1,714 ms
コンパイル使用メモリ 169,664 KB
実行使用メモリ 8,424 KB
最終ジャッジ日時 2023-10-17 09:25:05
合計ジャッジ時間 2,939 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
7,104 KB
testcase_01 AC 5 ms
7,104 KB
testcase_02 AC 5 ms
7,104 KB
testcase_03 AC 5 ms
7,104 KB
testcase_04 AC 5 ms
7,104 KB
testcase_05 AC 5 ms
7,104 KB
testcase_06 AC 5 ms
7,104 KB
testcase_07 AC 5 ms
7,104 KB
testcase_08 AC 5 ms
7,104 KB
testcase_09 AC 5 ms
7,104 KB
testcase_10 AC 8 ms
7,104 KB
testcase_11 AC 9 ms
7,104 KB
testcase_12 AC 9 ms
7,104 KB
testcase_13 AC 23 ms
8,424 KB
testcase_14 AC 397 ms
8,424 KB
testcase_15 AC 136 ms
7,632 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=200005,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N;
    vector<int> A(N);
    vector<int> B(1000001,0);
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    
    for(int i=0;i<N;i++){
        if(A[i]==1){
            B[1]=1;
            continue;
        }
        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