結果

問題 No.2708 Jewel holder
ユーザー loop0919loop0919
提出日時 2024-03-31 13:43:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 83 ms / 2,000 ms
コード長 627 bytes
コンパイル時間 154 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 75,580 KB
最終ジャッジ日時 2024-03-31 13:43:49
合計ジャッジ時間 1,726 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

ways = [(1, 0), (0, 1)]

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

def is_object(i, j):
    return (i < 0 or H <= i) or (j < 0 or W <= j) or A[i][j] == '#'

ans = 0

def dfs(now_i, now_j, cost):
    global ans
    for y, x in ways:
        next_i, next_j = now_i + y, now_j + x
        if is_object(next_i, next_j):
            continue
        next_cost = cost + (1 if A[next_i][next_j] == 'o' else -1)
        if next_cost < 0:
            continue
        if (next_i, next_j) == (H-1, W-1):
            ans += 1
        else:
            dfs(next_i, next_j, next_cost)

dfs(0, 0, 1)
print(ans)
0