結果

問題 No.390 最長の数列
ユーザー serser
提出日時 2018-01-02 18:38:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 817 bytes
コンパイル時間 1,082 ms
コンパイル使用メモリ 80,736 KB
実行使用メモリ 7,932 KB
最終ジャッジ日時 2023-08-24 16:56:02
合計ジャッジ時間 8,107 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,384 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 <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <climits>
#include <tuple>

using namespace std;

int n;
int nums[100000];
int dp[100000];
int f(int index, int cnt) {
    if (dp[index]==0) {
        dp[index] = cnt;
        for (int i=index+1; i<n; ++i) {
            if (nums[i]%nums[index]==0) {
                dp[index] = max(dp[index], f(i, cnt+1));
            }
        }
    }

    return dp[index];
}

int main() {
    scanf("%d", &n);    
    getchar();

    for(int i=0; i<n; i++) {
        scanf("%d", &nums[i]);   
    }
    std::sort(nums, &nums[n], std::less<int>());

    int max_cnt=0;
    for(int i=0; i<n; i++) {
        max_cnt=max(max_cnt, f(i, 1));
    }

    printf("%d\n", max_cnt);
    
    return 0;
}
0