-
Notifications
You must be signed in to change notification settings - Fork 0
/
treasurehunt.py
41 lines (33 loc) · 938 Bytes
/
treasurehunt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import sys
input = sys.stdin.readline
r, c = list(map(int, input().split()))
visited = [[False] * c for _ in range(r)]
grid = [list(input().strip()) for _ in range(r)]
# [row, column]
current = [0, 0]
steps = 0
while current[0] < r and current[0] >= 0 and current[1] < c and current[1] >= 0:
if visited[current[0]][current[1]] == True:
print("Lost")
exit(0)
visited[current[0]][current[1]] = True
if grid[current[0]][current[1]] == "T":
print(steps)
exit(0)
if grid[current[0]][current[1]] == "N":
steps += 1
current[0] -= 1
continue
if grid[current[0]][current[1]] == "S":
steps += 1
current[0] += 1
continue
if grid[current[0]][current[1]] == "W":
steps += 1
current[1] -= 1
continue
if grid[current[0]][current[1]] == "E":
steps += 1
current[1] += 1
continue
print("Out")