結果
問題 | No.2708 Jewel holder |
ユーザー | NP |
提出日時 | 2024-03-31 15:07:59 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,376 bytes |
コンパイル時間 | 286 ms |
コンパイル使用メモリ | 82,448 KB |
実行使用メモリ | 54,756 KB |
最終ジャッジ日時 | 2024-09-30 20:17:10 |
合計ジャッジ時間 | 1,833 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 36 ms
52,608 KB |
testcase_01 | AC | 38 ms
52,608 KB |
testcase_02 | AC | 38 ms
52,352 KB |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | AC | 36 ms
52,864 KB |
testcase_06 | AC | 39 ms
52,224 KB |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | AC | 36 ms
52,608 KB |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
ソースコード
def count_valid_routes(H, W, grid): dp = [[0]*W for _ in range(H)] dp[0][0] = 1 if grid[0][0] == 'o' else 0 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('x' in row for row in grid): for i in range(H): for j in range(W): if grid[i][j] == '#': continue if i > 0: dp[i][j] = max(dp[i][j], dp[i-1][j] + (grid[i][j] == 'o') - (grid[i][j] == 'x')) if j > 0: dp[i][j] = max(dp[i][j], dp[i][j-1] + (grid[i][j] == 'o') - (grid[i][j] == 'x')) if dp[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-1][j-1] = dp[i-2][j-1] + dp[i-1][j-2] 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))