#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pint;
#define x first
#define y second
int h, w, k, a[1004][1004], c[1004];
int f(int k) {
int ans = 0;
memset(c, 0, sizeof(c));
for (int i=1; i<=h; i++) {
for (int j=1; j<=w; j++) {
if (a[i][j] >= k) c[j]++;
else c[j] = 0;
}
stack<pint> st;
for (int j=1; j<=w+1; j++) {
int k = j;
while (!st.empty() and st.top().x > c[j]) {
ans = max(ans, st.top().x * (j - st.top().y));
k = st.top().y;
st.pop();
}
st.emplace(c[j], k);
}
}
return ans;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> h >> w >> k;
for (int i=1; i<=h; i++) for (int j=1; j<=w; j++) cin >> a[i][j];
int l = 0, r = 1e9 + 2;
while (l+1<r) {
int m = (l+r)/2;
if (f(m) >= k) l = m;
else r = m;
}
cout << l << ' ' << f(l) << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
688 KB |
Output is correct |
4 |
Correct |
2 ms |
688 KB |
Output is correct |
5 |
Correct |
2 ms |
688 KB |
Output is correct |
6 |
Correct |
2 ms |
752 KB |
Output is correct |
7 |
Correct |
2 ms |
752 KB |
Output is correct |
8 |
Correct |
6 ms |
1056 KB |
Output is correct |
9 |
Correct |
9 ms |
1756 KB |
Output is correct |
10 |
Correct |
22 ms |
1896 KB |
Output is correct |
11 |
Correct |
33 ms |
2716 KB |
Output is correct |
12 |
Correct |
22 ms |
3832 KB |
Output is correct |
13 |
Correct |
27 ms |
3832 KB |
Output is correct |
14 |
Correct |
56 ms |
4580 KB |
Output is correct |
15 |
Correct |
57 ms |
5128 KB |
Output is correct |
16 |
Correct |
63 ms |
6152 KB |
Output is correct |
17 |
Correct |
67 ms |
7104 KB |
Output is correct |
18 |
Correct |
154 ms |
10328 KB |
Output is correct |
19 |
Correct |
171 ms |
12624 KB |
Output is correct |
20 |
Correct |
338 ms |
18476 KB |
Output is correct |
21 |
Correct |
328 ms |
25228 KB |
Output is correct |
22 |
Correct |
435 ms |
35408 KB |
Output is correct |
23 |
Correct |
429 ms |
45052 KB |
Output is correct |
24 |
Correct |
270 ms |
47648 KB |
Output is correct |
25 |
Correct |
295 ms |
50640 KB |
Output is correct |