結果
問題 | No.971 いたずらっ子 |
ユーザー | tamato |
提出日時 | 2020-01-17 21:36:01 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,111 ms / 2,000 ms |
コード長 | 958 bytes |
コンパイル時間 | 161 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 181,012 KB |
最終ジャッジ日時 | 2024-04-25 01:56:37 |
合計ジャッジ時間 | 10,346 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1,111 ms
180,736 KB |
testcase_01 | AC | 1,096 ms
180,860 KB |
testcase_02 | AC | 831 ms
153,964 KB |
testcase_03 | AC | 982 ms
180,708 KB |
testcase_04 | AC | 922 ms
174,080 KB |
testcase_05 | AC | 980 ms
181,012 KB |
testcase_06 | AC | 741 ms
156,616 KB |
testcase_07 | AC | 95 ms
76,672 KB |
testcase_08 | AC | 279 ms
102,880 KB |
testcase_09 | AC | 263 ms
101,504 KB |
testcase_10 | AC | 76 ms
76,288 KB |
testcase_11 | AC | 44 ms
53,760 KB |
testcase_12 | AC | 41 ms
53,632 KB |
testcase_13 | AC | 60 ms
65,280 KB |
testcase_14 | AC | 84 ms
74,880 KB |
testcase_15 | AC | 59 ms
64,000 KB |
testcase_16 | AC | 46 ms
60,544 KB |
testcase_17 | AC | 41 ms
53,760 KB |
testcase_18 | AC | 43 ms
54,272 KB |
testcase_19 | AC | 41 ms
53,888 KB |
testcase_20 | AC | 41 ms
53,888 KB |
testcase_21 | AC | 42 ms
54,360 KB |
testcase_22 | AC | 42 ms
54,016 KB |
testcase_23 | AC | 40 ms
54,016 KB |
testcase_24 | AC | 40 ms
54,016 KB |
ソースコード
def main(): import sys from collections import deque input = sys.stdin.readline H, W = map(int, input().split()) grid = [] for _ in range(H): line = input().rstrip('\n') grid.append(line) d = [(0, 1), (1, 0), (-1, 0), (0, -1)] inf = float('inf') que = deque() que.append((0, 0)) seen = [[inf] * W for _ in range(H)] seen[0][0] = 0 while que: h, w = que.popleft() for dh, dw in d: h_new, w_new = h+dh, w+dw if 0 <= h_new < H and 0 <= w_new < W: if seen[h_new][w_new] > 10**9: que.append((h_new, w_new)) if grid[h_new][w_new] == '.': seen[h_new][w_new] = min(seen[h_new][w_new], seen[h][w] + 1) else: seen[h_new][w_new] = min(seen[h_new][w_new], seen[h][w] + 1 + h_new + w_new) print(seen[-1][-1]) if __name__ == '__main__': main()