-
Notifications
You must be signed in to change notification settings - Fork 0
/
3085.cpp
60 lines (52 loc) · 1 KB
/
3085.cpp
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
60
#include<cstdio>
#include<algorithm>
using namespace std;
int n;
char arr[50][50];
int Candy() {
int result = 1;
for (int i = 0; i < n; i++) {
int temp = 1;
for (int j = 1; j < n; j++) {
if (arr[i][j - 1] == arr[i][j]) temp++;
else {
result = max(result, temp);
temp = 1;
}
}
result = max(result, temp);
}
for (int i = 0; i < n; i++) {
int temp = 1;
for (int j = 1; j < n; j++) {
if (arr[j - 1][i] == arr[j][i]) temp++;
else {
result = max(result, temp);
temp = 1;
}
}
result = max(result, temp);
}
return result;
}
int main() {
int MAX = -1;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
scanf(" %c", &arr[i][j]);
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n - 1; j++) {
swap(arr[i][j], arr[i][j + 1]);
MAX = max(MAX, Candy());
swap(arr[i][j], arr[i][j + 1]);
swap(arr[j][i], arr[j + 1][i]);
MAX = max(MAX, Candy());
swap(arr[j][i], arr[j + 1][i]);
}
}
printf("%d\n", MAX);
return 0;
}