import sys
input = sys.stdin.readline
graph = []
n = int(input())
cntList = [0] * n
for _ in range(n):
myList = list(input())
graph.append(myList)
for i in range(n):
for j in range(n):
# 1 친구 수 더하기
if graph[i][j] == 'Y':
cntList[i] += 1
# 2 친구 수 더하기
else:
for j2 in range(n):
if graph[i][j2] == 'Y' and graph[j2][j] == 'Y' and j != i:
cntList[i] += 1
break
print(max(cntList))
import sys
from collections import deque
input = sys.stdin.readline
def bfs(graph, i, j, w, h):
dy = [0, 0, 1, -1, 1, 1, -1, -1]
dx = [1, -1, 0, 0, -1, 1, -1, 1]
dq = deque()
dq.append((i,j))
graph[i][j] = -1
while dq:
v = dq.popleft()
y = v[0]
x = v[1]
for i in range(8):
ny = y + dy[i]
nx = x + dx[i]
if ny >= 0 and ny < h and nx >= 0 and nx < w and graph[ny][nx] == 1:
dq.append((ny,nx))
graph[ny][nx] = -1
while True:
w, h = map(int, input().split())
if w == 0 and h == 0:
break
cnt = 0
graph = []
result = 0
for _ in range(h):
graph.append(list(map(int, input().split())))
for i in range(h):
for j in range(w):
if graph[i][j] == 1:
bfs(graph, i, j, w, h)
cnt += 1
print(cnt)
미안함미다 풀지 못했습니다.
import sys
input = sys.stdin.readline
board = []
n = int(input())
for _ in range(n):
myList = list(map(int, input().split()))
board.append(myList)
# 알고리즘을 작성해봅시다.
# 총 4가지의 경우의 수
# 를 5번 할 수 있으니
# 경우의 수는 4 x 4 x 4 x 4 x 4 니 2의 10승 이니 1024개
# 1024를 모두 고려할까? ㅇㅇ 이건 모두 고려해야 하는 것 같아
# --------------------------------------------------------------
# 고려하면 각각의 경우에 대해서 몇번의 연산이 필요하지??
# -> N*N*N*N -> 400 * 400 N줄에 대해서 * 합치는 연산 * 빈공간 없애는 연산(N^2)
# 거기에 최대값 찾는 알고리즘 까지?? ㄷㄷ N * N 이건 따로 뺄 수 있을 것 같긴 하네
뭐지? 답지 봐도 이해가 안됨..