문제: https://www.acmicpc.net/problem/3085
문제
Little Ivan is bored at math class so he decided to play popular game called "Bomboni". At the beginning all fields of N×N square board contain candies (not necessarily of same color). When its his turn player should swap two neighbouring (up, down, left or right) candies of different color and then pick some sequence (in row or column) of same color candies which he will take and eat.
Initial board configuration is given, help Ivan and write a program which will calculate maximal number of candies he can win in the first move.
입력
In the first line of standard input there is one integer N (3 ≤ N ≤ 50), board dimensions.
In next N lines initial board configuration is given, j-th character in i-th row denotes color of candy at square (i, j) : C (red), P (blue), Z (green), Y (yellow). It will always be possible to make first move.
출력
In the first and only line of standard output print the maximal number of candies Ivan can win in the first move.
예제 입력 1
5 YCPZY CYZZP CCPPP YCYZC CPPZZ
예제 출력 1
4
힌트
swapping candies Y and C in 4th row Ivan gets sequence CCCC in first column.
출처
Olympiad > Croatian Highschool Competitions in Informatics > 2012 > Junior Croatian Olympiad in Informatics - Exam #1 1번
'Algorithm, Data structure > Solved Algorithmic Problem' 카테고리의 다른 글
BAEKJOON 1932 - 숫자삼격형 (0) | 2018.02.01 |
---|---|
BAEKJOON 1149 - RGB거리 (0) | 2017.12.22 |
BAEKJOON 1158 - 조세퍼스 문제 (0) | 2017.12.21 |
BAEKJOON 2343 - 기타 레슨 (0) | 2017.09.16 |
BAEKJOON 1992 - 쿼드트리 (0) | 2017.01.05 |