시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB275469100627032.068%

문제

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

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

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

입력

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

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

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

출력

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

예제 입력 1

3
CCP
CCP
PPC

예제 출력 1

3

예제 입력 2

4
PPPP
CYZY
CCPY
PPCC

예제 출력 2

4

예제 입력 3

5
YCPZY
CYZZP
CCPPP
YCYZC
CPPZZ

예제 출력 3

4

힌트

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

W3sicHJvYmxlbV9pZCI6IjMwODUiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWMwYWNcdWQwZDUgXHVhYzhjXHVjNzg0IiwiZGVzY3JpcHRpb24iOiI8cD5cdWMwYzFcdWFkZmNcdWM3NzRcdWIyOTQgXHVjNWI0XHViODM4XHVjNzQ0IFx1YzgwMVx1YzVkMCAmcXVvdDtcdWJkMDRcdWJjZjRcdWIyYzggKEJvbWJvbmkpJnF1b3Q7IFx1YWM4Y1x1Yzc4NFx1Yzc0NCBcdWM5OTBcdWFjYThcdWQ1ODhcdWIyZTQuPFwvcD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XQiOiI8cD5JbiB0aGUgZmlyc3QgYW5kIG9ubHkgbGluZSBvZiBzdGFuZGFyZCBvdXRwdXQgcHJpbnQgdGhlIG1heGltYWwgbnVtYmVyIG9mIGNhbmRpZXMgSXZhbiBjYW4gd2luIGluIHRoZSBmaXJzdCBtb3ZlLiZuYnNwOzxcL3A+XHJcbiIsImhpbnQiOiI8cD5TZWNvbmQgdGVzdCBleGFtcGxlIGV4cGxhbmF0aW9uOiBpbiBmaXJzdCByb3cgd2Ugc2VlIHNlcXVlbmNlIFBQUFAsIHNvIHN3YXBwaW5nIGFueSB0d28gY2FuZGllcyBpbiBvdGhlciByb3dzIGZpcnN0IHJvdyByZW1haW4gdW5jaGFuZ2VkIHNvIEl2YW4gY2FuIHRha2UgaXQuPFwvcD5cclxuXHJcbjxwPlRoaXJkIHRlc3QgZXhhbXBsZSBleHBsYW5hdGlvbjogc3dhcHBpbmcgY2FuZGllcyBZIGFuZCBDIGluIDR0aCByb3cgSXZhbiBnZXRzIHNlcXVlbmNlIENDQ0MgaW4gZmlyc3QgY29sdW1uLjxcL3A+XHJcbiIsIm9yaWdpbmFsIjoiMSIsImh0bWxfdGl0bGUiOiIwIiwicHJvYmxlbV9sYW5nX3Rjb2RlIjoiRW5nbGlzaCJ9XQ==

출처

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

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