SW Expert Academy
SW ํ๋ก๊ทธ๋๋ฐ ์ญ๋ ๊ฐํ์ ๋์์ด ๋๋ ๋ค์ํ ํ์ต ์ปจํ ์ธ ๋ฅผ ํ์ธํ์ธ์!
swexpertacademy.com
from collections import deque
T = int(input())
for tc in range(1,T+1):
row,col = map(int,input().split())
arr=[list(map(int,input().split())) for _ in range(row)]
sy,sx=map(int,input().split())
visit = [[0] * col for _ in range(row)]
time=1 #1์ผ๋ถํฐ๋๊น
lst=[]
q =deque()
q.append((sy,sx,time))
visit[sy][sx]= 1
lst.append(arr[sy][sx]+time)
def bfs():
if q:
temp=q[0][2] #๋ ์ง
global time,lst
while q:
ny,nx,nmove =q.popleft()
if nmove !=temp:
q.append((ny,nx,nmove))
break
directy=[-1,1,0,0]
directx=[0,0,-1,1]
for i in range(4):
dy=ny+directy[i]
dx=nx+directx[i]
if 0<=dy<row and 0<=dx<col:
if arr[dy][dx]>0 and visit[dy][dx]==0:
visit[dy][dx]=1
q.append((dy,dx,nmove+1))
lst.append(arr[dy][dx]+time)
Mflower=0
Mtime=0
def calculation(): #์ต๋ ๊ฝ์ ๊ฐฏ์์ ๊ทธ์ ํด๋นํ๋ ํด๋น ์ผ ๊ตฌํ๊ธฐ
global Mflower,Mtime,time,lst
flower = 0
lst.sort()
for i in range(len(lst)):
if lst[i]>time:
lst=lst[i:]
break
flower=len(lst)
if Mflower<flower:
Mflower=flower
Mtime = time
while q: #q๊ฐ ์์ ๋๊น์ง while๋ฌธ ๋๊ธฐ
calculation()
time += 1
bfs()
print(f'#{tc} {Mtime}์ผ {Mflower}๊ฐ')
'Problem Solving > SWEA' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
swea1865. ๋์ฒ ์ด์ ์ผ ๋ถ๋ฐฐ (0) | 2022.06.02 |
---|---|
swea4021.์๋ฆฌ์ฌ (0) | 2022.04.07 |
swea2117.ํ ๋ฐฉ๋ฒ ์๋น์ค (0) | 2022.04.07 |
swea.14195 ๋ฏธ์๋ฌผ ๊ด์ฐฐ (0) | 2022.04.06 |
swea. ์ ๊ธฐ๋ฒ์ค (0) | 2022.03.06 |
๋๊ธ