-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcityGame_UVA1330.cpp
110 lines (96 loc) · 2.73 KB
/
cityGame_UVA1330.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
110
#include <bits/stdc++.h>
using namespace std;
ifstream fin("cityGame_UVA1330.in");
ofstream fout("cityGame_UVA1330.out");
int main()
{
int testCase; fin >> testCase;
for (int t = 1; t <= testCase; ++t)
{
int n, m; fin >> n >> m;
vector<vector<char>> a(n + 1, vector<char>(m + 1, 0));
for (int y = 1; y <= n; ++y)
{
for (int x = 1; x <= m; ++x)
{
fin >> a[y][x];
}
}
vector<vector<int>> maxH(n + 2, vector<int>(m + 2, 0)),
maxL(n + 2, vector<int>(m + 2, 0)),
maxR(n + 2, vector<int>(m + 2, 0));
for (int x = 1; x <= m; ++x)
{
maxL[0][x] = INT_MAX;
maxR[0][x] = INT_MAX;
}
for (int y = 1; y <= n; ++y)
{
int last = 0;
for (int x = 1; x <= m; ++x)
{
if (a[y][x] == 'R')
{
maxH[y][x] = 0;
}
else
{
maxH[y][x] = maxH[y - 1][x] + 1;
}
}
last = 0;
for (int x = 1; x <= m; ++x)
{
if (y == 1 && x == 1)
{
for (int __s = 0; __s == 0; ++__s);
}
if (a[y][x] == 'R')
{
last = x;
}
else
{
if (a[y - 1][x] == 'R')
{
maxL[y][x] = x - last - 1;
}
else
{
maxL[y][x] = min(maxL[y - 1][x], x - last - 1);
}
}
}
last = m + 1;
for (int x = m; x >= 1; --x)
{
if (a[y][x] == 'R')
{
last = x;
}
else
{
if (a[y - 1][x] == 'R')
{
maxR[y][x] = last - x - 1;
}
else
{
maxR[y][x] = min(maxR[y - 1][x], last - x - 1);
}
}
}
}
int ans = 0;
for (int y = 1; y <= n; ++y)
{
for (int x = 1; x <= m; ++x)
{
int size = maxH[y][x] * (maxL[y][x] + maxR[y][x] + 1);
ans = max(ans, size);
}
}
fout << ans * 3 << '\n';
}
return 0;
}