def search(maps, r, c):
if 0 <= r <= 99 and 0 <= c <= 99:
if maps[r][c] == 1:
# 왼쪽 길 존재
if c>0 and maps[r][c-1] == 1:
while c > 0 and maps[r][c - 1] == 1:
c -= 1
return c
# 오른쪽 길
if c < 99 and maps[r][c+1] == 1:
while c < 99 and maps[r][c + 1] == 1:
c += 1
return c
return c
T = 10
for test_case in range(1, T + 1):
maps = [[] for i in range(100)]
col = -1
test_num = int(input())
for row in range(100):
maps[row] = list(map(int, input().split()))
if 2 in maps[row]:
col = maps[row].index(2)
# 위로 올라가면서 좌우 탐색
for rows in range(99, 0, -1):
col = search(maps, rows-1, col)
print("#" + str(test_case), col)
D4 난이도도 무난한 듯 하다.
기본적으로 삼성 코테는 복잡한 구현
, 탐색(dfs, bfs, 완전탐색 with 자료구조 최적화)
의 문제를 많이 좋아하는 듯 보인다.
시간초과는 가장 주의해야 할 점이지만, 이 정도 난이도에선 그다지 신경 쓸 필요 없이 구현만 되면 되는 것 같다.