結果

問題 No.2708 Jewel holder
ユーザー koshihkarikoshihkari
提出日時 2024-03-31 14:13:46
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 820 bytes
コンパイル時間 204 ms
コンパイル使用メモリ 11,904 KB
実行使用メモリ 10,112 KB
最終ジャッジ日時 2024-03-31 14:13:52
合計ジャッジ時間 1,397 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import sys
sys.setrecursionlimit(1000000)
h, w = map(int, input().split())
grid = []
for _ in range(h):
    line = list(input())
    grid.append(line)
minimum_count = 100
ans = 0

def dfs(i, j, stone, visited):
    # print(i, j)
    if i < 0 or i >= h or j < 0 or j >= w:
        return
    global minimum_count, ans
    visited[i][j] = True
    if grid[i][j] == "o":
        stone += 1
    if grid[i][j] == "x":
        stone -= 1
    if stone < 0:
        return
    if i == h-1 and j == w-1:
        ans += 1
        return
    for dx, dy in [[0, 1], [1, 0]]:
        if i+dx < 0 or i+dx >= h or j+dy < 0 or j+dy >= w:
            continue
        if grid[i+dx][j+dy] == "#":
            continue
        else:
            dfs(i+dx, j+dy, stone, visited.copy())

dfs(0, 0, 0, [[False]*w for _ in range(h)])
print(ans)
0