結果

問題 No.390 最長の数列
ユーザー xuzijian629xuzijian629
提出日時 2018-10-29 23:07:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 877 bytes
コンパイル時間 2,275 ms
コンパイル使用メモリ 205,836 KB
実行使用メモリ 5,760 KB
最終ジャッジ日時 2024-04-29 23:54:59
合計ジャッジ時間 6,028 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,248 KB
testcase_01 WA -
testcase_02 AC 3 ms
5,376 KB
testcase_03 WA -
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,760 KB
testcase_15 AC 3 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, 1);
    for (int i = 1; i < n; i++) {
        i64 t = 1;
        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++) {
        ans = max(ans, dp[i]);
    }
    cout << ans << endl;
}
0