結果

問題 No.390 最長の数列
ユーザー xuzijian629xuzijian629
提出日時 2018-10-29 23:08:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 923 bytes
コンパイル時間 2,233 ms
コンパイル使用メモリ 205,944 KB
実行使用メモリ 5,632 KB
最終ジャッジ日時 2024-04-29 23:56:18
合計ジャッジ時間 5,338 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,248 KB
testcase_01 AC 3 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 RE -
testcase_06 RE -
testcase_07 AC 3 ms
5,376 KB
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 AC 284 ms
5,632 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
権限があれば一括ダウンロードができます

ソースコード

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(101010, -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