結果

問題 No.390 最長の数列
ユーザー confconf
提出日時 2016-07-09 00:07:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,723 ms / 5,000 ms
コード長 627 bytes
コンパイル時間 755 ms
コンパイル使用メモリ 80,524 KB
実行使用メモリ 8,200 KB
最終ジャッジ日時 2023-07-25 17:01:03
合計ジャッジ時間 6,562 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 81 ms
8,064 KB
testcase_06 AC 2,723 ms
8,200 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 5 ms
4,376 KB
testcase_10 AC 343 ms
8,156 KB
testcase_11 AC 370 ms
8,004 KB
testcase_12 AC 323 ms
8,028 KB
testcase_13 AC 428 ms
7,024 KB
testcase_14 AC 617 ms
8,008 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 7 ms
4,380 KB
testcase_18 AC 11 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <map>
using namespace std;

int main(){
    int N;
    cin>>N;
    map<int,int> DP;
    int Xmax=0;
    for(int i=0;i<N;i++){
        int x;
        cin>>x;
        DP[x]=1;
        Xmax=max(x,Xmax);
    }
    for(auto ite=DP.begin(); ite!=DP.end();ite++){
        int x=ite->first;
        for(int i=2;x*i<=Xmax;i++){
            if(DP.find(x*i)!=DP.end()){
                DP[x*i]=max(DP[x*i],DP[x]+1);
            }
        }
    }
    int ans=1;
    for(auto ite=DP.begin(); ite!=DP.end();ite++){
        ans=max(ans,ite->second);
    }
    cout<<ans<<endl;
    return 0;
}
0