-
Notifications
You must be signed in to change notification settings - Fork 0
/
CTGAME.java
73 lines (71 loc) · 1.3 KB
/
CTGAME.java
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
package ques;
import java.util.Scanner;
import java.util.Stack;
public class CTGAME {
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
int t=scanner.nextInt();
while(t>0){
t--;
int r=scanner.nextInt();
int c=scanner.nextInt();
int[][] arr=new int[r][c];
for(int i=0;i<r;i++){
for(int j=0;j<c;j++){
char x=scanner.next().charAt(0);
if(x=='R')
arr[i][j]=0;
else
arr[i][j]=1;
}
}
int[] temp=new int[c];
int max=0;
for(int i=0;i<r;i++){
for(int j=0;j<c;j++){
if(arr[i][j]==0)
temp[j]=0;
else
temp[j]+=1;
}
max=Math.max(max, area(temp));
}
System.out.println(max*3);
String ss=scanner.nextLine();
}
}
public static int area(int[] a){
Stack<Integer> st=new Stack<Integer>();
int maxarea=0;
int top=0;
int area=0;
int i=0;
for(i=0;i<a.length;){
if(st.isEmpty() || a[st.peek()]<=a[i]){
st.add(i);
i++;
}
else{
top=st.pop();
if(st.isEmpty())
area=a[top]*i;
else
area=a[top]*(i-st.peek()-1);
if(area>maxarea){
maxarea=area;
}
}
}
while(!st.isEmpty()){
top=st.pop();
if(st.isEmpty())
area=a[top]*i;
else
area=a[top]*(i-st.peek()-1);
if(area>maxarea){
maxarea=area;
}
}
return maxarea;
}
}