結果

問題 No.2708 Jewel holder
ユーザー pitPpitP
提出日時 2024-03-31 13:44:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 1,004 bytes
コンパイル時間 142 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 59,860 KB
最終ジャッジ日時 2024-03-31 13:44:05
合計ジャッジ時間 1,530 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
53,460 KB
testcase_01 AC 36 ms
53,460 KB
testcase_02 AC 37 ms
53,460 KB
testcase_03 AC 33 ms
53,460 KB
testcase_04 AC 34 ms
53,460 KB
testcase_05 AC 35 ms
53,460 KB
testcase_06 AC 36 ms
53,460 KB
testcase_07 AC 36 ms
53,460 KB
testcase_08 AC 35 ms
53,460 KB
testcase_09 AC 35 ms
53,460 KB
testcase_10 AC 34 ms
53,460 KB
testcase_11 AC 35 ms
53,460 KB
testcase_12 AC 37 ms
53,460 KB
testcase_13 AC 35 ms
53,460 KB
testcase_14 AC 36 ms
53,460 KB
testcase_15 AC 37 ms
53,460 KB
testcase_16 AC 37 ms
53,460 KB
testcase_17 AC 42 ms
59,860 KB
testcase_18 AC 40 ms
59,508 KB
testcase_19 AC 41 ms
59,508 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

H, W = map(int, input().split())
A = [input() for _ in range(H)]

# dp[i][j][cnt]
dp = [[[0 for _ in range(H + W + 1)] for _ in range(W)] for _ in range(H)]
dp[0][0][1] = 1

for i in range(H):
    for j in range(W):
        for c in range(H + W + 1):
            if dp[i][j][c] == 0:
                continue

            # (i, j) -> (i + 1, j)
            if i + 1 < H and A[i + 1][j] != '#':
                if A[i + 1][j] == 'o' and c + 1 <= H + W:
                    dp[i + 1][j][c + 1] += dp[i][j][c]
                elif A[i + 1][j] == 'x' and c - 1 >= 0:
                    dp[i + 1][j][c - 1] += dp[i][j][c]

            # (i, j) -> (i, j + 1)
            if j + 1 < W and A[i][j + 1] != '#':
                if A[i][j + 1] == 'o' and c + 1 <= H + W:
                    dp[i][j + 1][c + 1] += dp[i][j][c]
                elif A[i][j + 1] == 'x' and c - 1 >= 0:
                    dp[i][j + 1][c - 1] += dp[i][j][c]

ans = 0
for c in range(H + W + 1):
    ans += dp[H - 1][W - 1][c]
print(ans)
0