結果

問題 No.2374 ASKT Subsequences
ユーザー InTheBloomInTheBloom
提出日時 2023-07-08 00:46:25
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 486 ms / 2,000 ms
コード長 1,342 bytes
コンパイル時間 1,457 ms
コンパイル使用メモリ 163,176 KB
実行使用メモリ 4,928 KB
最終ジャッジ日時 2023-09-29 02:19:30
合計ジャッジ時間 17,251 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 408 ms
4,928 KB
testcase_01 AC 406 ms
4,860 KB
testcase_02 AC 407 ms
4,828 KB
testcase_03 AC 414 ms
4,848 KB
testcase_04 AC 411 ms
4,888 KB
testcase_05 AC 406 ms
4,876 KB
testcase_06 AC 416 ms
4,928 KB
testcase_07 AC 409 ms
4,824 KB
testcase_08 AC 414 ms
4,916 KB
testcase_09 AC 410 ms
4,916 KB
testcase_10 AC 411 ms
4,880 KB
testcase_11 AC 413 ms
4,792 KB
testcase_12 AC 411 ms
4,920 KB
testcase_13 AC 410 ms
4,844 KB
testcase_14 AC 417 ms
4,832 KB
testcase_15 AC 417 ms
4,832 KB
testcase_16 AC 415 ms
4,792 KB
testcase_17 AC 425 ms
4,808 KB
testcase_18 AC 434 ms
4,856 KB
testcase_19 AC 431 ms
4,836 KB
testcase_20 AC 455 ms
4,760 KB
testcase_21 AC 465 ms
4,756 KB
testcase_22 AC 450 ms
4,832 KB
testcase_23 AC 437 ms
4,792 KB
testcase_24 AC 436 ms
4,832 KB
testcase_25 AC 423 ms
4,824 KB
testcase_26 AC 480 ms
4,816 KB
testcase_27 AC 486 ms
4,816 KB
testcase_28 AC 458 ms
4,820 KB
testcase_29 AC 471 ms
4,840 KB
testcase_30 AC 444 ms
4,824 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;

// 解説AC 部分列を捜査するという時点で基本的には全探索しかないため、DPっぽいなーっていうのは気づいていた。
// ただ、Kの値を固定できたらなーっていう考えに気づくのが遅すぎたため、既存の方針で何とかできないか考えてしまった。

void main () {
    int N = readln.chomp.to!int;
    int[] A = readln.split.to!(int[]);

    long ans = 0;
    foreach (K; 1..2001) {
        ans += solve(N, A, K);
    }

    writeln(ans);
}

auto solve (int N, int[] A, int K) {
    // Kさえ固定できてしまえば更新がだいぶんさぼれるぞい
    const sup = 2001;

    // dp[j][k] := i項目まで見たとき、a_1がjである部分列のk個目をとれる場合の数
    long[][] dp = new long[][](sup, 4);

    // initialize
    dp[A[0]][0] = 1;

    foreach (i; 1..N) {
        // K==3
        if (1 <= A[i]-K-11) {
            dp[A[i]-K-11][3] += dp[A[i]-K-11][2];
        }

        // K==2
        if (1 <= A[i]-10) {
            dp[A[i]-10][2] += dp[A[i]-10][1];
        }

        // K==1
        if (1 <= A[i]-K-10) {
            dp[A[i]-K-10][1] += dp[A[i]-K-10][0];
        }

        // K==0
        dp[A[i]][0]++;
    }

    long res = 0;
    foreach (j; 1..sup) {
        res += dp[j][$-1];
    }

    return res;
}
0