結果

問題 No.390 最長の数列
ユーザー Ai3ShotaAi3Shota
提出日時 2018-05-11 02:25:37
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 750 bytes
コンパイル時間 1,493 ms
コンパイル使用メモリ 149,408 KB
実行使用メモリ 8,340 KB
最終ジャッジ日時 2023-09-10 12:14:00
合計ジャッジ時間 8,716 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 WA -
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define MOD 1000000007

using namespace std;

int N;
vector<int> numset;
int dp[1000001] = {0};

int rec(int perv = 0, int count = 0){
    
    if(count == N) return count;
    if(dp[perv] != 0 && dp[perv] >= count) return dp[perv];
    
    int i, j;
    for(i = 0; i < N; ++i){
        if(perv == 0 || (numset[i] != perv && numset[i] % perv == 0)) dp[perv] = ((j = rec(numset[i], count + 1)) > dp[perv]) ? j : dp[perv];
    }
    
    return dp[perv] = (count > dp[perv]) ? count : dp[perv];
}


int main(void){
    
    cin >> N;
    
    int i, j;
    for(i = 0; i < N; ++i){
        cin >> j;
        numset.push_back(j);
    }
    
    sort(numset.begin(), numset.end());
    cout << rec() << endl;
    
    return 0;
}
0