結果
問題 | No.2928 Gridpath |
ユーザー | loop0919 |
提出日時 | 2024-09-13 01:18:41 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 118 ms / 2,000 ms |
コード長 | 1,195 bytes |
コンパイル時間 | 158 ms |
コンパイル使用メモリ | 82,344 KB |
実行使用メモリ | 76,412 KB |
最終ジャッジ日時 | 2024-09-13 01:18:44 |
合計ジャッジ時間 | 2,437 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
53,784 KB |
testcase_01 | AC | 37 ms
53,084 KB |
testcase_02 | AC | 96 ms
76,016 KB |
testcase_03 | AC | 38 ms
53,984 KB |
testcase_04 | AC | 37 ms
53,180 KB |
testcase_05 | AC | 48 ms
61,436 KB |
testcase_06 | AC | 90 ms
76,100 KB |
testcase_07 | AC | 39 ms
52,824 KB |
testcase_08 | AC | 37 ms
52,640 KB |
testcase_09 | AC | 72 ms
71,112 KB |
testcase_10 | AC | 40 ms
53,296 KB |
testcase_11 | AC | 38 ms
53,664 KB |
testcase_12 | AC | 38 ms
53,356 KB |
testcase_13 | AC | 39 ms
53,128 KB |
testcase_14 | AC | 38 ms
53,236 KB |
testcase_15 | AC | 92 ms
76,072 KB |
testcase_16 | AC | 87 ms
76,112 KB |
testcase_17 | AC | 92 ms
76,140 KB |
testcase_18 | AC | 94 ms
76,004 KB |
testcase_19 | AC | 118 ms
76,412 KB |
testcase_20 | AC | 38 ms
53,416 KB |
testcase_21 | AC | 96 ms
75,896 KB |
testcase_22 | AC | 93 ms
76,220 KB |
ソースコード
ways = [(0, 1), (0, -1), (1, 0), (-1, 0)] H, W = map(int, input().split()) S_i, S_j = map(lambda x: int(x) - 1, input().split()) G_i, G_j = map(lambda x: int(x) - 1, input().split()) grid = [[0 for _ in range(W)] for _ in range(H)] stack = [(0, S_i, S_j)] # 0: 行きがけ, 1: 戻りがけ ans = 0 while stack: state, now_i, now_j = stack.pop() if now_i == G_i and now_j == G_j: ans += state continue if state == 0: grid[now_i][now_j] += 1 for di, dj in ways: next_i, next_j = now_i + di, now_j + dj if 0 <= next_i < H and 0 <= next_j < W: grid[next_i][next_j] += 1 for di, dj in ways: next_i, next_j = now_i + di, now_j + dj if not (0 <= next_i < H and 0 <= next_j < W): continue if grid[next_i][next_j] <= 1: stack.append((1, next_i, next_j)) stack.append((0, next_i, next_j)) else: grid[now_i][now_j] -= 1 for di, dj in ways: next_i, next_j = now_i + di, now_j + dj if 0 <= next_i < H and 0 <= next_j < W: grid[next_i][next_j] -= 1 print(ans)