Skip to content

Commit 4d6703c

Browse files
authored
[20260224] BOJ / P3 / 최대 직사각형 / 권혁준
1 parent f055f84 commit 4d6703c

File tree

1 file changed

+100
-0
lines changed

1 file changed

+100
-0
lines changed
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class Main {
6+
7+
static class IOManager {
8+
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
9+
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
10+
static StringTokenizer st = new StringTokenizer("");
11+
12+
private IOManager(){}
13+
14+
static String nextLine() throws Exception {
15+
String line = br.readLine();
16+
st = new StringTokenizer(line);
17+
return line;
18+
}
19+
20+
static String nextToken() throws Exception {
21+
while (!st.hasMoreTokens())
22+
nextLine();
23+
return st.nextToken();
24+
}
25+
26+
static int nextInt() throws Exception {
27+
return Integer.parseInt(nextToken());
28+
}
29+
30+
static long nextLong() throws Exception {
31+
return Long.parseLong(nextToken());
32+
}
33+
34+
static double nextDouble() throws Exception {
35+
return Double.parseDouble(nextToken());
36+
}
37+
38+
static void write(String content) throws Exception {
39+
bw.write(content);
40+
}
41+
42+
public static void close() throws Exception {
43+
bw.flush();
44+
bw.close();
45+
br.close();
46+
}
47+
}
48+
49+
//
50+
51+
static int N, M;
52+
static int[] arr;
53+
54+
public static void main(String[] args) throws Exception {
55+
N = IOManager.nextInt();
56+
M = IOManager.nextInt();
57+
while (Math.min(N, M) > 0) {
58+
int ans = 0;
59+
arr = new int[M];
60+
for (int i = 0; i < N; i++) {
61+
for (int j = 0, a; j < M; j++) {
62+
a = IOManager.nextInt();
63+
if (a == 1) {
64+
arr[j]++;
65+
}
66+
else {
67+
arr[j] = 0;
68+
}
69+
}
70+
ans = Math.max(ans, histogram(arr));
71+
}
72+
73+
IOManager.write(ans + "\n");
74+
N = IOManager.nextInt();
75+
M = IOManager.nextInt();
76+
}
77+
IOManager.close();
78+
}
79+
80+
public static int histogram(int[] hist) {
81+
int ret = 0;
82+
Stack<int[]> stack = new Stack<>();
83+
for (int i = 0; i < hist.length; i++) {
84+
int idx = i;
85+
while (!stack.isEmpty() && stack.peek()[0] > hist[i]) {
86+
ret = Math.max(ret, stack.peek()[0] * (i - stack.peek()[1]));
87+
idx = stack.peek()[1];
88+
stack.pop();
89+
}
90+
stack.push(new int[]{ hist[i], idx });
91+
}
92+
while (!stack.isEmpty()) {
93+
ret = Math.max(ret, stack.peek()[0] * (hist.length - stack.peek()[1]));
94+
stack.pop();
95+
}
96+
return ret;
97+
}
98+
99+
}
100+
```

0 commit comments

Comments
 (0)