시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 128 MB 4009 1233 943 31.837%

문제

상근이는 어렸을 적에 "봄보니 (Bomboni)" 게임을 즐겨했다.

가장 처음에 N×N크기에 사탕을 채워 놓는다. 사탕의 색은 모두 같지 않을 수도 있다. 상근이는 사탕의 색이 다른 인접한 두 칸을 고른다. 그 다음 고른 칸에 들어있는 사탕을 서로 교환한다. 이제, 모두 같은 색으로 이루어져 있는 가장 긴 연속 부분(행 또는 열)을 고른 다음 그 사탕을 모두 먹는다.

사탕이 채워진 상태가 주어졌을 때, 상근이가 먹을 수 있는 사탕의 최대 개수를 구하는 프로그램을 작성하시오.

입력

첫째 줄에 보드의 크기 N이 주어진다. (3 ≤ N ≤ 50)

다음 N개 줄에는 보드에 채워져 있는 사탕의 색상이 주어진다. 빨간색은 C, 파란색은 P, 초록색은 Z, 노란색은 Y로 주어진다.

사탕의 색이 다른 인접한 두 칸이 존재하는 입력만 주어진다.

출력

첫째 줄에 상근이가 먹을 수 있는 사탕의 최대 개수를 출력한다.

예제 입력 1

5
YCPZY
CYZZP
CCPPP
YCYZC
CPPZZ

예제 출력 1

4

힌트

4번 행의 Y와 C를 바꾸면 사탕 네 개를 먹을 수 있다.

W3sicHJvYmxlbV9pZCI6IjMwODUiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWMwYWNcdWQwZDUgXHVhYzhjXHVjNzg0IiwiZGVzY3JpcHRpb24iOiI8cD5cdWMwYzFcdWFkZmNcdWM3NzRcdWIyOTQgXHVjNWI0XHViODM4XHVjNzQ0IFx1YzgwMVx1YzVkMCAmcXVvdDtcdWJkMDRcdWJjZjRcdWIyYzggKEJvbWJvbmkpJnF1b3Q7IFx1YWM4Y1x1Yzc4NFx1Yzc0NCBcdWM5OTBcdWFjYThcdWQ1ODhcdWIyZTQuPFwvcD5cclxuXHJcbjxwPlx1YWMwMFx1YzdhNSBcdWNjOThcdWM3NGNcdWM1ZDAgTiZ0aW1lcztOXHV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hbiB3aW4gaW4gdGhlIGZpcnN0IG1vdmUuJm5ic3A7PFwvcD5cclxuIiwiaGludCI6IjxwPnN3YXBwaW5nIGNhbmRpZXMgWSBhbmQgQyBpbiA0dGggcm93IEl2YW4gZ2V0cyBzZXF1ZW5jZSBDQ0NDIGluIGZpcnN0IGNvbHVtbi48XC9wPlxyXG4iLCJvcmlnaW5hbCI6IjEiLCJwcm9ibGVtX2xhbmdfY29kZSI6Ilx1YzYwMVx1YzViNCJ9XQ==

출처

Olympiad > Croatian Highschool Competitions in Informatics > 2012 > Junior Croatian Olympiad in Informatics - Exam #1 1번

  • 데이터를 추가한 사람: 10jobss
  • 문제를 번역한 사람: baekjoon
  • 문제의 오타를 찾은 사람: jh05013
  • 잘못된 조건을 찾은 사람: juhyun16