-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path143_D_1.py
More file actions
38 lines (37 loc) · 752 Bytes
/
Copy path143_D_1.py
File metadata and controls
38 lines (37 loc) · 752 Bytes
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
ans=0
n,m=map(int,input().split(' '))
a=list()
b=[]
c=[[1,0],[-1,0],[0,1],[0,-1]]
l=0
r=0
p=0
for i in range(n):
a.append(input())
for i in range(n):
for j in range(m):
if a[i][j]=='V':
b.append([i,j,0])
break
#print(b[l][0]+c[0][0])
flag=0
while True:
for i in range(4):
x=b[l][0]+c[i][0]
y=b[l][1]+c[i][1]
if x not in range(n) or y not in range(m):
continue
if a[x][y]=='E':
#print([x,y])
ans=b[l][2]+1
flag=1
break
if a[x][y]=='.':
r+=1
b.append([x,y,b[l][2]+1])
a[x]=a[x][:y]+'#'+a[x][y+1:m]
#print([x,y])
if flag==1:
break
l+=1
print(ans)