-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbruteforce3085.cpp
More file actions
59 lines (58 loc) · 1.17 KB
/
bruteforce3085.cpp
File metadata and controls
59 lines (58 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int check(vector<string> &a){
int n = a.size();
int ans = 1; // 답: answer
for(int i=0; i<n; i++){
int cnt= 1;
for(int j=1; j<n; j++){
// i 행 같은게 있는지 쭉 확인
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++){
// i열 같은게 있는지 확인
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;
}