結果

問題 No.2708 Jewel holder
ユーザー Ekiben542Ekiben542
提出日時 2024-03-31 15:02:23
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,353 bytes
コンパイル時間 197 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 53,460 KB
最終ジャッジ日時 2024-03-31 15:02:25
合計ジャッジ時間 1,803 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

def count_valid_routes(H, W, grid):
    dp = [[0 for _ in range(W+1)] for _ in range(H+1)]
    dp[1][1] = 1
    gems = [[0 for _ in range(W+1)] for _ in range(H+1)]
    gems[1][1] = 1 if grid[0][0] == 'o' else 0
    if any('#' in row for row in grid):
        for i in range(1, H+1):
            for j in range(1, W+1):
                if i == 1 and j == 1:
                    continue
                if grid[i-1][j-1] == '#':
                    continue
                dp[i][j] = dp[i-1][j] + dp[i][j-1]
                gems[i][j] = max(gems[i-1][j], gems[i][j-1]) + (grid[i-1][j-1] == 'o') - (grid[i-1][j-1] == 'x')
                if gems[i][j] < 0:
                    dp[i][j] = 0
    else:
        for i in range(1, H+1):
            for j in range(1, W+1):
                if i == 1 and j == 1:
                    continue
                if grid[i-1][j-1] == '#':
                    continue
                if grid[i-1][j-1] == 'o':
                    gems[i][j] = max(gems[i-1][j], gems[i][j-1]) + 1
                else:
                    gems[i][j] = max(gems[i-1][j], gems[i][j-1]) - 1
                if gems[i][j] >= 0:
                    dp[i][j] = dp[i-1][j] + dp[i][j-1]
    return dp[-1][-1] if dp[-1][-1] >= 0 else 0
H, W = map(int, input().split())
grid = [input() for _ in range(H)]
print(count_valid_routes(H, W, grid))
0