結果
問題 | No.2708 Jewel holder |
ユーザー | NP |
提出日時 | 2024-03-31 15:02:23 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,353 bytes |
コンパイル時間 | 341 ms |
コンパイル使用メモリ | 82,592 KB |
実行使用メモリ | 54,500 KB |
最終ジャッジ日時 | 2024-09-30 20:11:54 |
合計ジャッジ時間 | 2,049 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 36 ms
52,352 KB |
testcase_01 | WA | - |
testcase_02 | AC | 38 ms
52,480 KB |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | AC | 37 ms
52,352 KB |
testcase_07 | AC | 36 ms
52,736 KB |
testcase_08 | AC | 36 ms
52,736 KB |
testcase_09 | WA | - |
testcase_10 | AC | 39 ms
52,608 KB |
testcase_11 | AC | 40 ms
52,352 KB |
testcase_12 | AC | 40 ms
52,608 KB |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | AC | 37 ms
52,480 KB |
testcase_16 | WA | - |
testcase_17 | AC | 37 ms
52,736 KB |
testcase_18 | AC | 38 ms
52,480 KB |
testcase_19 | AC | 38 ms
52,396 KB |
ソースコード
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))