#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
const int N = 1003;
int n, m, k, ans_c, ans_a, a[N][N], b[N][N];
bool check(int x) {
for (int i = n; i >= 1; --i)
for (int j = m; j >= 1; --j)
if (a[i][j] >= x) b[i][j] = b[i + 1][j] + 1;
else b[i][j] = 0;
int area = 0;
deque < pair < int , int > > dq;
for (int i = 1; i <= n; ++i) {
for (int j = m; j >= 1; --j) {
int id = j;
while (dq.size() && dq.back().f >= b[i][j]) {
id = dq.back().s;
dq.pop_back();
}
area = max(area, b[i][j] * (id - j + 1));
dq.push_back({b[i][j], id});
}
while (dq.size()) {
area = max(area, dq.front().f * dq.front().s);
dq.pop_back();
}
}
if (area >= k) {
ans_c = x;
ans_a = area;
return true;
}
return false;
}
main () {
ios::sync_with_stdio(false);
cin.tie(NULL), cout.tie(NULL);
cin >> n >> m >> k;
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= m; ++j)
cin >> a[i][j];
int l = 1, r = 1e9, mid;
while (l <= r) {
mid = ((l + r) >> 1);
if (check(mid))
l = mid + 1;
else
r = mid - 1;
}
cout << ans_c << " " << ans_a << "\n";
}
Compilation message
burrow.cpp:44:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
44 | main () {
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Incorrect |
1 ms |
456 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |