結果

問題 No.2673 A present from B
ユーザー dyktr_06dyktr_06
提出日時 2024-03-16 00:18:41
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 1,396 bytes
コンパイル時間 2,081 ms
コンパイル使用メモリ 170,984 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-16 00:18:50
合計ジャッジ時間 7,845 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 839 ms
6,676 KB
testcase_07 AC 837 ms
6,676 KB
testcase_08 AC 812 ms
6,676 KB
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 WA -
testcase_13 RE -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 RE -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 571 ms
6,676 KB
testcase_22 AC 2 ms
6,676 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 1 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;

void main () {
    int N, M; readln.read(N, M);
    auto A = readln.split.to!(int[]);

    auto dp = new int[][](M + 1, N + 1);
    int[] ans;

    BinaryHeap!(Tuple!(int, int)[], "b[1] < a[1]") PQ = [];

    foreach (bob; 2..N+1) {
        foreach (d; dp) d[] = int.max;

        for (int i = 0; bob + i <= N; i++) dp[0][bob + i] = i;
        for (int i = 0; 1 <= bob - i; i++) dp[0][bob - i] = i;

        foreach (i; 0..M) {
            dp[i + 1][] = dp[i][];

            // 操作
            dp[i + 1][A[i] + 1] = dp[i][A[i]];
            dp[i + 1][A[i]] = dp[i][A[i] + 1];
            
            // 右となり
            int mn = N;
            for (int j = 0; j < M; j++) {
                dp[i + 1][j] = min(dp[i + 1][j], mn);
            	mn = min(mn, dp[i + 1][j]);
            	mn++;
            }
            
            // 左となり
            mn = N;
            for (int j = M - 1; j >= 0; j--) {
                dp[i + 1][j] = min(dp[i + 1][j], mn);
            	mn = min(mn, dp[i + 1][j]);
            	mn++;
            }
        }

        ans ~= dp[M][1];
    }

    foreach (i, a; ans) {
        write(a, i == ans.length - 1 ? '\n' : ' ');
    }
}

void read (T...) (string S, ref T args) {
    import std.conv : to;
    import std.array : split;
    auto buf = S.split;
    foreach (i, ref arg; args) {
        arg = buf[i].to!(typeof(arg));
    }
}
0