結果

問題 No.390 最長の数列
ユーザー tubo28tubo28
提出日時 2016-07-08 23:13:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 991 bytes
コンパイル時間 1,806 ms
コンパイル使用メモリ 163,072 KB
実行使用メモリ 19,328 KB
最終ジャッジ日時 2024-04-21 07:53:38
合計ジャッジ時間 7,450 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(c) begin(c), end(c)
//#define fill(c,v) fill(decltype(v)*(begin(c)), decltype(v)*(end(c)), v)

int n;
int have[1000010];
int dp[1000010];

int rec(int k){
    int &res = dp[k];
    if(res != -1) return res;
    if(k == 1) return res = 1;
    res = 1;
    for(int i = 1; i*i <= k; ++i){
        if(k%i == 0){
            if(have[i]) res = max(res, rec(i)+1);
            if(i != 1 && have[k/i]) res = max(res, rec(k/i)+1);
        }
    }
    return res;
}

decltype(0) main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    while(cin >> n){
        memset(dp, -1, sizeof dp);
        memset(have, 0, sizeof have);
        int x;
        rep(i,n) cin >> x, have[x] = true;
        rep(i,1000010) if(have[i]) rec(i);
        // rep(i,20) cout << dp[i] << ' ';
        // cout << endl;
        cout << *max_element(dp,dp+100010) << endl;
    }
}
0