結果
| 問題 |
No.2708 Jewel holder
|
| コンテスト | |
| ユーザー |
👑 |
| 提出日時 | 2024-03-31 13:43:47 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 88 ms / 2,000 ms |
| コード長 | 627 bytes |
| コンパイル時間 | 162 ms |
| コンパイル使用メモリ | 82,304 KB |
| 実行使用メモリ | 75,728 KB |
| 最終ジャッジ日時 | 2024-09-30 18:17:51 |
| 合計ジャッジ時間 | 1,613 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 |
ソースコード
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)