-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3085.cpp
109 lines (100 loc) · 1.46 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// 3085. 사탕 게임
// 2019.09.04
// 브루트 포스
#include<iostream>
#include<algorithm>
using namespace std;
char map[51][51];
int n;
int ans;
void check()
{
for (int i = 0; i < n; i++)
{
int cnt = 0;
for (int j = 0; j < n; j++)
{
char cur = map[i][j];
int idx = 0;
// 아래 방향 검사
if (i + 1 < n)
{
cnt = 1;
idx = i;
while (1)
{
if (map[idx + 1][j] == cur && idx + 1 < n)
{
cnt++;
idx++;
}
else
{
break;
}
}
ans = max(cnt, ans);
}
// 오른쪽 방향 검사
if (j + 1 < n)
{
cnt = 1;
idx = j;
while (1)
{
if (map[i][idx + 1] == cur && idx + 1 < n)
{
cnt++;
idx++;
}
else
{
break;
}
}
ans = max(cnt, ans);
}
}
}
}
int main()
{
cin >> n;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
cin >> map[i][j];
}
}
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
// 아래 방향 검사
if (i + 1 < n)
{
char k = map[i][j];
map[i][j] = map[i + 1][j];
map[i + 1][j] = k;
check();
k = map[i][j];
map[i][j] = map[i + 1][j];
map[i + 1][j] = k;
}
// 오른쪽 방향 검사
if (j + 1 < n)
{
char k = map[i][j];
map[i][j] = map[i][j + 1];
map[i][j + 1] = k;
check();
k = map[i][j];
map[i][j] = map[i][j + 1];
map[i][j + 1] = k;
}
}
}
cout << ans << endl;
return 0;
}