結果

問題 No.390 最長の数列
ユーザー tubo28tubo28
提出日時 2016-07-08 23:14:14
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 956 ms / 5,000 ms
コード長 992 bytes
コンパイル時間 1,454 ms
コンパイル使用メモリ 163,112 KB
実行使用メモリ 19,276 KB
最終ジャッジ日時 2024-04-10 08:51:19
合計ジャッジ時間 6,806 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
19,180 KB
testcase_01 AC 7 ms
19,104 KB
testcase_02 AC 7 ms
19,004 KB
testcase_03 AC 6 ms
19,168 KB
testcase_04 AC 7 ms
19,080 KB
testcase_05 AC 956 ms
19,196 KB
testcase_06 AC 607 ms
19,136 KB
testcase_07 AC 8 ms
19,056 KB
testcase_08 AC 8 ms
19,248 KB
testcase_09 AC 6 ms
19,276 KB
testcase_10 AC 690 ms
19,072 KB
testcase_11 AC 678 ms
18,948 KB
testcase_12 AC 784 ms
19,188 KB
testcase_13 AC 495 ms
19,264 KB
testcase_14 AC 231 ms
18,960 KB
testcase_15 AC 8 ms
19,080 KB
testcase_16 AC 7 ms
19,088 KB
testcase_17 AC 37 ms
19,148 KB
testcase_18 AC 60 ms
19,148 KB
権限があれば一括ダウンロードができます

ソースコード

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+1000010) << endl;
    }
}
0