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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# 3055 탈출
# BFS
# Python 780ms
dx = [0,1,0,-1]
dy = [-1,0,1,0]
def move(x,y):
global stop
SET = False
for i in range(4):
nx = x + dx[i]
ny = y + dy[i]
if 0 <= nx < M and 0 <= ny < N:
if board[x][y] == '*': # 물
if board[nx][ny] == '.'or board[nx][ny] == 'G':
board[nx][ny] = '*'
if board[x][y] == 'S':# 비버
if board[nx][ny]=='.': # 이동
SET =True
board[nx][ny] = 'S'
record[nx][ny] = record[x][y] + 1
if board[nx][ny]=='D': # 종료
record[nx][ny] = record[x][y] + 1
stop = True
print(record[nx][ny])
break
if SET:
board[x][y] = 'G'
M, N = map(int, input().split())
board = [list(input()) for _ in range(M)]
record = [[0]*N for i in range(M)]
stop = False
count = M*N
while not stop:
water_lst = []
dudu_lst = []
for i in range(M):
for j in range(N):
if board[i][j]=='*':
water_lst.append((i,j))
if board[i][j]=='S':
dudu_lst.append((i,j))
for p in water_lst:
move(p[0], p[1])
for p in dudu_lst:
move(p[0],p[1])
if stop:
break
count -= 1
if count <0:
print('KAKTUS')
break
|
'프로그래밍' 카테고리의 다른 글
[백준 3184 파이썬 ] 양 (0) | 2020.02.25 |
---|---|
[백준 7459 파이썬] 토마토 (0) | 2020.02.25 |
[백준 6603 파이썬] 로또 (0) | 2020.02.25 |
[백준 7562 파이썬] 나이트 이동 (0) | 2020.02.25 |
[백준 10026 파이썬] 적록색약 (0) | 2020.02.24 |