結果

問題 No.390 最長の数列
ユーザー ama_nukoama_nuko
提出日時 2018-06-11 15:06:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 799 bytes
コンパイル時間 941 ms
コンパイル使用メモリ 91,944 KB
実行使用メモリ 11,820 KB
最終ジャッジ日時 2023-09-13 02:57:50
合計ジャッジ時間 6,803 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 4 ms
10,744 KB
testcase_02 WA -
testcase_03 AC 4 ms
10,716 KB
testcase_04 WA -
testcase_05 AC 1,106 ms
11,548 KB
testcase_06 WA -
testcase_07 AC 5 ms
10,708 KB
testcase_08 AC 4 ms
10,868 KB
testcase_09 AC 5 ms
10,832 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 567 ms
11,488 KB
testcase_14 WA -
testcase_15 AC 5 ms
11,044 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

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];

    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[a[i] / j] + 1);
            if(j * j != a[i]){
                dp[a[i]] = max(dp[a[i]], dp[j] + 1);
            }
        }
    }
    cout << dp[a[n-1]] << endl;

    return 0;
}
0