3085번: 사탕 게임
첫째 줄에 상근이가 먹을 수 있는 사탕의 최대 개수를 출력한다.
www.acmicpc.net
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int check(vector<string> &a) {
int n = a.size();
int ans = 1;
for (int i=0; i<n; i++) {
int cnt = 1;
for (int j=1; j<n; j++) {
if (a[i][j] == a[i][j-1]) {
cnt += 1;
} else {
cnt = 1;
}
if (ans < cnt) ans = cnt;
}
cnt = 1;
for (int j=1; j<n; j++) {
if (a[j][i] == a[j-1][i]) {
cnt += 1;
} else {
cnt = 1;
}
if (ans < cnt) ans = cnt;
}
}
return ans;
}
int main() {
int n;
cin >> n;
vector<string> a(n);
for (int i=0; i<n; i++) {
cin >> a[i];
}
int ans = 0;
for (int i=0; i<n; i++) {
for (int j=0; j<n; j++) {
if (j+1 < n) {
swap(a[i][j], a[i][j+1]);
int temp = check(a);
if (ans < temp) ans = temp;
swap(a[i][j], a[i][j+1]);
}
if (i+1 < n) {
swap(a[i][j], a[i+1][j]);
int temp = check(a);
if (ans < temp) ans = temp;
swap(a[i][j], a[i+1][j]);
}
}
}
cout << ans << '\n';
return 0;
}
'Problem set' 카테고리의 다른 글
[백준] 1107 리모컨 (0) | 2021.01.19 |
---|---|
[백준] 1476 날짜 계산 (0) | 2021.01.19 |
[백준] 2309 일곱 난쟁이 (0) | 2021.01.19 |
[백준] 17413: 단어 뒤집기 2 (0) | 2020.12.29 |
[백준] 17087: 숨바꼭질 6 (0) | 2020.12.29 |