結果

問題 No.390 最長の数列
ユーザー xuzijian629xuzijian629
提出日時 2018-10-29 23:08:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,102 ms / 5,000 ms
コード長 924 bytes
コンパイル時間 2,050 ms
コンパイル使用メモリ 205,080 KB
実行使用メモリ 12,728 KB
最終ジャッジ日時 2023-08-12 09:37:37
合計ジャッジ時間 8,333 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
11,092 KB
testcase_01 AC 4 ms
11,100 KB
testcase_02 AC 4 ms
11,144 KB
testcase_03 AC 4 ms
10,840 KB
testcase_04 AC 4 ms
11,148 KB
testcase_05 AC 1,102 ms
12,676 KB
testcase_06 AC 679 ms
12,720 KB
testcase_07 AC 4 ms
11,128 KB
testcase_08 AC 5 ms
11,144 KB
testcase_09 AC 4 ms
11,104 KB
testcase_10 AC 774 ms
12,580 KB
testcase_11 AC 771 ms
12,680 KB
testcase_12 AC 780 ms
12,620 KB
testcase_13 AC 561 ms
12,028 KB
testcase_14 AC 267 ms
12,728 KB
testcase_15 AC 4 ms
11,140 KB
testcase_16 AC 5 ms
11,084 KB
testcase_17 AC 39 ms
11,036 KB
testcase_18 AC 62 ms
11,068 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

int main() {
    int n;
    cin >> n;
    vi as(n), rev(1010101, -1);
    for (int i = 0; i < n; i++) {
        cin >> as[i];
    }
    sort(as.begin(), as.end());
    for (int i = 0; i < n; i++) {
        rev[as[i]] = i;
    }
    vi dp(n);
    dp[0] = 1;
    for (int i = 1; i < n; i++) {
        i64 t = 0;
        for (int j = 1; j * j <= as[i]; j++) {
            if (as[i] % j == 0) {
                if (rev[j] != -1) {
                    t = max(t, dp[rev[j]] + 1);
                }
                if (rev[as[i] / j] != -1) {
                    t = max(t, dp[rev[as[i] / j]] + 1);
                }
            }
        }
        dp[i] = t;
    }
    i64 ans = 1;
    for (int i = 1; i < n; i++) {
        // cout << dp[i] << endl;
        ans = max(ans, dp[i]);
    }
    cout << ans << endl;
}
0