[๋ฐฑ์ค-3085] ์ฌํ ๊ฒ์ / Python
๐ Problem Solving/Baekjoon
3085๋ฒ: ์ฌํ ๊ฒ์
์์ 3์ ๊ฒฝ์ฐ 4๋ฒ ํ์ Y์ C๋ฅผ ๋ฐ๊พธ๋ฉด ์ฌํ ๋ค ๊ฐ๋ฅผ ๋จน์ ์ ์๋ค.
www.acmicpc.net
import sys
input = sys.stdin.readline
n = int(input())
color = [list(map(str, input().rstrip())) for _ in range(n)]
def check(color):
cnt = 0
for i in range(n):
rowCnt = 1
colCnt = 1
for j in range(n - 1):
if color[i][j] == color[i][j + 1]:
rowCnt += 1
else:
cnt = max(cnt, rowCnt)
rowCnt = 1
if color[j][i] == color[j + 1][i]:
colCnt += 1
else:
cnt = max(cnt, colCnt)
colCnt = 1
cnt = max(cnt, rowCnt, colCnt)
return cnt
answer = 0
for i in range(n):
for j in range(n - 1):
if color[i][j] != color[i][j + 1]:
color[i][j], color[i][j + 1] = color[i][j + 1], color[i][j]
answer = max(answer, check(color))
color[i][j], color[i][j + 1] = color[i][j + 1], color[i][j]
if color[j][i] != color[j + 1][i]:
color[j][i], color[j + 1][i] = color[j + 1][i], color[j][i]
answer = max(answer, check(color))
color[j][i], color[j + 1][i] = color[j + 1][i], color[j][i]
print(answer)
ํด์ค
ํ๊ณผ ์ด ๋ณ๋ก ํ์ฌ ๊ฐ์ ๋ค์ ๊ฐ๊ณผ ๋ฐ๊ฟ์ค๋ค. check ํจ์๋ฅผ ํตํด ๊ฐ์ ์์๋ก ์ด๋ฃจ์ด์ง ๊ฐ์ฅ ๊ธด ๊ธธ์ด๋ฅผ ๊ตฌํ๋ค. check ํจ์๊ฐ ์ข ๋ฃ๋๋ฉด ๋ฐ๊ฟ์ค ๊ฐ์ ์๋๋๋ก ๋๋ฆฐ๋ค.
'๐ Problem Solving > Baekjoon' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค-1051] ์ซ์ ์ ์ฌ๊ฐํ / Python (0) | 2021.06.21 |
---|---|
[๋ฐฑ์ค-5567] ๊ฒฐํผ์ / Python (0) | 2021.06.21 |
[๋ฐฑ์ค-10973] ์ด์ ์์ด / Python (0) | 2021.06.21 |
[๋ฐฑ์ค-1748] ์ ์ด์ด ์ฐ๊ธฐ 1 / Python (0) | 2021.06.19 |
[๋ฐฑ์ค-1292] ์ฝ๊ฒ ํธ๋ ๋ฌธ์ / Python (0) | 2021.06.19 |