๋ฌธ์
https://www.acmicpc.net/problem/3085
ํ์ด
# ๋ฐฑ์ค 3085๋ฒ ๋ฌธ์ - ์ฌํ ๊ฒ์
n = int(input())
candy =[list(input()) for _ in range(n)]
dx = [0,0,1,-1]
dy = [1,-1,0,0]
result = 0
temp = ''
for i in range(n):
for j in range(n):
for k in range(4):
nx = dx[k] + j
ny = dy[k] + i
if nx>=0 and ny>=0 and nx<n and ny<n:
if candy[i][j] != candy[ny][nx]:
temp = candy[i][j]
candy[i][j] = candy[ny][nx]
candy[ny][nx] = temp
row_cnt = 1
col_cnt = 1
for l in range(n-1):
if candy[i][l] == candy[i][l+1]:
row_cnt +=1
else:
row_cnt = 1
if candy[l][j] == candy[l+1][j]:
col_cnt += 1
else:
col_cnt=1
result = max(result, row_cnt, col_cnt)
if candy[i][j] != candy[ny][nx]:
candy[ny][nx] = candy[i][j]
candy[i][j] = temp
print(result)
๋ธ๋ฃจํธ ํฌ์ค ๋ฌธ์ ์ด๋ค.
'๐๏ธ Algorithm > ๐ฉ ๋ฐฑ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๐ฉ [๋ฐฑ์ค] [Python] [Gold3] 14890๋ฒ_๊ฒฝ์ฌ๋ก (0) | 2023.06.19 |
---|---|
๐ฉ [๋ฐฑ์ค] [Python] [Silver2] 2477๋ฒ_์ฐธ์ธ๋ฐญ (0) | 2023.06.16 |
๐ฉ [๋ฐฑ์ค] [Python] [Silver3] 15903๋ฒ_์นด๋ ํฉ์ฒด ๋์ด (0) | 2023.05.29 |
๐ฉ [๋ฐฑ์ค] [Python] [Silver3] 2346๋ฒ_ํ์ ํฐ๋จ๋ฆฌ๊ธฐ (0) | 2023.05.29 |
๐ฉ [๋ฐฑ์ค] [Python] [Gold4] 1339๋ฒ_๋จ์ด ์ํ (0) | 2023.05.15 |