結果

問題 No.390 最長の数列
ユーザー ama_nukoama_nuko
提出日時 2018-06-11 15:48:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,066 ms / 5,000 ms
コード長 918 bytes
コンパイル時間 854 ms
コンパイル使用メモリ 96,632 KB
実行使用メモリ 11,824 KB
最終ジャッジ日時 2023-09-13 03:00:28
合計ジャッジ時間 7,181 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
10,816 KB
testcase_01 AC 5 ms
10,880 KB
testcase_02 AC 5 ms
10,748 KB
testcase_03 AC 6 ms
10,816 KB
testcase_04 AC 6 ms
10,868 KB
testcase_05 AC 1,066 ms
11,492 KB
testcase_06 AC 671 ms
11,824 KB
testcase_07 AC 5 ms
10,832 KB
testcase_08 AC 6 ms
10,812 KB
testcase_09 AC 5 ms
10,708 KB
testcase_10 AC 755 ms
11,680 KB
testcase_11 AC 754 ms
11,572 KB
testcase_12 AC 756 ms
11,676 KB
testcase_13 AC 553 ms
11,500 KB
testcase_14 AC 271 ms
11,676 KB
testcase_15 AC 5 ms
10,748 KB
testcase_16 AC 5 ms
10,752 KB
testcase_17 AC 39 ms
10,712 KB
testcase_18 AC 61 ms
10,976 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

signed main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    sort(a.begin(), a.end());

    vector<int> dp(1e6 + 1);
    rep(i, n){
        for(int j = 1; j * j <= a[i]; j++){
            if(a[i] % j != 0){
                continue;
            }
            dp[a[i]] = max(dp[a[i]], dp[j] + 1);
            if(j != 1){
                dp[a[i]] = max(dp[a[i]], dp[a[i] / j] + 1);
            }
        }
    }
    int ans = 0;
    rep(i, 1e6+1){
        if(ans < dp[i]){
            ans = dp[i];
        }
    }
    cout << ans << endl;


    return 0;
}
0