-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCTGAME.cs
110 lines (100 loc) · 3.42 KB
/
CTGAME.cs
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
using System;
using System.Collections.Generic;
using System.Text;
namespace AlgoSolution
{
struct Histro
{
public int Height;
public int index;
}
class METEORAK
{
static void Main()
{
Run();
Console.ReadLine();
}
static int MaxAreaUnderHistrogram(int[] num, int n)
{
Stack<Histro> stack = new Stack<Histro>();
int maxArea = Int32.MinValue;
for (int i = 0; i <= n; i++)
{
while (stack.Count > 0 && (i == n || stack.Peek().Height > num[i]))
{
Histro toProcess = stack.Pop();
int left = -1;
if (stack.Count > 0)
left = stack.Peek().index;
int areaCovered = toProcess.Height * (i - left - 1);
if (maxArea < areaCovered)
maxArea = areaCovered;
}
if (i < n)
{
stack.Push(new Histro() { Height = num[i], index = i });
}
}
return maxArea;
}
static void Run()
{
int t = int.Parse(Console.ReadLine());
while (t > 0)
{
string[] strFirst = Console.ReadLine().Split();
int N = int.Parse(strFirst[0]);
int M = int.Parse(strFirst[1]);
//int K = int.Parse(strFirst[2]);
int[,] landMines = new int[N, M];
for (int i = 0; i < N; i++)
{
string[] strLandMine = Console.ReadLine().Split();
for (int j = 0; j < M; j++)
{
landMines[i, j] = strLandMine[j] == "F" ? 0 : 1;
}
}
#region
int maxArea = Int32.MinValue;
for (int top = 0; top < 1; top++)
{
int[,] tmp = new int[N, M];
for (int bottom = 0; bottom < N; bottom++)
{
int[] tmparr = new int[M];
for (int j = 0; j < M; j++)
{
if (landMines[bottom, j] == 1)
{
tmp[bottom, j] = 0;
tmparr[j] = 0;
}
else
{
if (bottom - 1 >= 0)
{
tmp[bottom, j] = tmp[bottom - 1, j] + 1;
tmparr[j] = tmp[bottom - 1, j] + 1; ;
}
else
{
tmp[bottom, j] = 1;
tmparr[j] = 1;
}
}
}
int localMaxArea = MaxAreaUnderHistrogram(tmparr, M);
if (localMaxArea > maxArea)
maxArea = localMaxArea;
}
}
#endregion
Console.WriteLine(maxArea * 3);
Console.ReadLine();
t--;
}
}
}
}