#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <stack>
#include <queue>
#include <deque>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>-
using namespace std;
//using namespace __gnu_pbds;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
// template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// order_of_key (k) : Number of items strictly smaller than k .
// find_by_order(k) : K-th element in a set (counting from zero).
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define pb push_back
#define ppb pop_back
#define mkp make_pair
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define show(a) cerr << #a <<" -> "<< a <<" "
#define nl cerr <<"\n"
//#define int ll
const int N = 1005;
const int oo = 1e9 + 5;
int n, m, k, a[N][N], h[N], l[N];
stack <int> st;
int check(int x) {
for (int j = 1; j <= m; ++j) { h[j] = 0; }
int mx = 0;
for (int i = 1; i <= n; ++i) {
// l[j]
while (sz(st)) { st.pop(); }
st.push(0); h[0] = 0;
for (int j = 1; j <= m; ++j) {
if (a[i][j] >= x) { h[j] = h[j] + 1; }
else { h[j] = 0; }
while (sz(st) && h[st.top()] >= h[j]) { st.pop(); }
if (sz(st)) { l[j] = st.top()+1; }
st.push(j);
}
// r
while (sz(st)) { st.pop(); }
st.push(m+1); h[m+1] = 0;
for (int j = m; j >= 1; --j) {
while (sz(st) && h[st.top()] >= h[j]) { st.pop(); }
if (sz(st)) {
int r = st.top()-1;
mx = max(mx, (r - l[j] + 1) * h[j]);
}
st.push(j);
}
}
if (mx >= k) { return mx; }
return 0;
}
void solve() {
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 = oo;
while (l < r) {
int mid = (l + r + 1) / 2;
if (check(mid)) l = mid;
else r = mid - 1;
}
cout << l <<" "<< check(l) <<"\n";
}
main () {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int tests = 1;
//cin >> tests;
while (tests --) {
solve();
}
return 0;
}
/*
Just Chalish!
3 3 3
1 1 1
1 2 2
1 2 2
*/
Compilation message
burrow.cpp:93:8: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
93 | main () {
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
492 KB |
Output is correct |
5 |
Correct |
1 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
492 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
7 ms |
768 KB |
Output is correct |
9 |
Correct |
13 ms |
1260 KB |
Output is correct |
10 |
Correct |
30 ms |
1388 KB |
Output is correct |
11 |
Correct |
71 ms |
1900 KB |
Output is correct |
12 |
Correct |
37 ms |
2540 KB |
Output is correct |
13 |
Correct |
38 ms |
1132 KB |
Output is correct |
14 |
Correct |
107 ms |
2540 KB |
Output is correct |
15 |
Correct |
111 ms |
2668 KB |
Output is correct |
16 |
Correct |
124 ms |
3180 KB |
Output is correct |
17 |
Correct |
129 ms |
2924 KB |
Output is correct |
18 |
Correct |
312 ms |
5612 KB |
Output is correct |
19 |
Correct |
344 ms |
5100 KB |
Output is correct |
20 |
Correct |
655 ms |
9116 KB |
Output is correct |
21 |
Correct |
676 ms |
10092 KB |
Output is correct |
22 |
Correct |
792 ms |
13932 KB |
Output is correct |
23 |
Correct |
796 ms |
14076 KB |
Output is correct |
24 |
Correct |
500 ms |
6892 KB |
Output is correct |
25 |
Correct |
543 ms |
7276 KB |
Output is correct |