fromcollectionsimportdequedx=[0,1,0,-1]dy=[1,0,-1,0]forTinrange(int(input())):N,M=map(int,input().split())arr=[input()for_inrange(N)]visited=[[-1for_inrange(M)]for_inrange(N)]q=deque([])foriinrange(N):forjinrange(M):ifarr[i][j]=="W":q.append([i,j])visited[i][j]=0total=0whileq:x,y=q.popleft()foriinrange(4):cx=x+dx[i]cy=y+dy[i]if0<=cx<Nand0<=cy<Mandvisited[cx][cy]==-1:visited[cx][cy]=visited[x][y]+1q.append([cx,cy])total+=visited[cx][cy]print(f'#{T+1}{total}')# 오랜만에 다중 시작점 BFS
D4_11592_크루즈 컨트롤
1
2
3
4
5
6
7
8
9
10
11
12
13
forTinrange(int(input())):D,N=map(int,input().split())# D: 총 거리 S=[]for_inrange(N):k,s=map(int,input().split())# k : 위치 / s : 속도S.append((D-k)/s)a=max(S)print(f'#{T+1}{D/a}')# D2 난이도...
defcheck():# 가로 판단foriinrange(4):if'.'notinarr[i]and'O'notinarr[i]:return'X won'if'.'notinarr[i]and'X'notinarr[i]:return'O won'# 세로 판단을 위한 리스트 생성col=[arr[j][i]forjinrange(4)]if'.'notincoland'O'notincol:return'X won'if'.'notincoland'X'notincol:return'O won'# 우상단 대각선 판단rUp=[arr[i][i]foriinrange(4)]if'.'notinrUpand'O'notinrUp:return'X won'elif'.'notinrUpand'X'notinrUp:return'O won'# 좌상단 대각선 판단lUP=[arr[i][3-i]foriinrange(4)]if'.'notinlUPand'O'notinlUP:return'X won'elif'.'notinlUPand'X'notinlUP:return'O won'# 그밖의 경우.foriinrange(4):forjinrange(4):ifarr[i][j]=='.':return'Game has not completed'return'Draw'N=int(input())forTinrange(N):arr=[list(input())for_inrange(4)]ifT<N-1:_=input()print(f'#{T+1}{check()}')# T의 숫자를 고려하는 것에 애먹었으나, # 문제에 T는 최대 1개로 설정. # 즉, T의 숫자를 별도로 카운트 하지 않아도 됨.