結果

問題 No.2708 Jewel holder
ユーザー InTheBloomInTheBloom
提出日時 2024-03-31 13:41:14
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,466 bytes
コンパイル時間 2,429 ms
コンパイル使用メモリ 163,036 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-31 13:41:23
合計ジャッジ時間 3,147 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import std;

void main () {
    int H, W; readln.read(H, W);
    auto A = new string[](H);

    foreach (i; 0..H) A[i] = readln.chomp;

    auto dp = new int[][][](H, W, H * W + 1);
    // dp[i][j][k] := (i, j)に宝石k個で至る場合の数

    dp[0][0][1] = 1;

    foreach (i; 0..H) {
        foreach (j; 0..W) {
            foreach (k; 0..H * W + 1) {
                // 右
                if (i + 1 < H) {
                    char c = A[i + 1][j];
                    if (c == 'o') {
                        if (k < H * W) dp[i + 1][j][k + 1] += dp[i][j][k];
                    }

                    if (c == 'x') {
                        if (0 < k) dp[i + 1][j][k - 1] += dp[i][j][k];
                    }
                }

                // 下
                if (j + 1 < W) {
                    char c = A[i][j + 1];
                    if (c == 'o') {
                        if (k < H * W) dp[i][j + 1][k + 1] += dp[i][j][k];
                    }

                    if (c == 'x') {
                        if (0 < k) dp[i][j + 1][k - 1] += dp[i][j][k];
                    }
                }
            }
        }
    }

    long ans = 0;
    foreach (k; 0..H * W + 1) {
        ans += dp[H - 1][W - 1][k];
    }

    writeln(ans);
}

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