#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define ld long double
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
template <typename T> using ord_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int n0 = 1003;
int n, m, k, a[n0][n0], dp[n0][n0], l[n0], r[n0];
vector <int> v;
int get(int x) {
int res = 0;
for (int j = 1; j <= m; j++) {
for (int i = 1; i <= n; i++)
dp[i][j] = (a[i][j] >= x) ? (dp[i][j - 1] + 1) : 0;
v.clear();
for (int i = 1; i <= n; i++) {
while (!v.empty() && dp[v.back()][j] >= dp[i][j])
v.pop_back();
if (v.empty()) l[i] = 1;
else l[i] = v.back() + 1;
v.pb(i);
}
v.clear();
for (int i = n; i >= 1; i--) {
while (!v.empty() && dp[v.back()][j] >= dp[i][j])
v.pop_back();
if (v.empty()) r[i] = n;
else r[i] = v.back() - 1;
v.pb(i);
res = max(res, (r[i] - l[i] + 1) * dp[i][j]);
}
}
return res;
}
int main() {
ios_base::sync_with_stdio(false), cin.tie(NULL);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif
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 = (int)1e9 + 1;
while (l < r - 1) {
int mid = l + r >> 1;
if (get(mid) >= k) l = mid;
else r = mid;
}
cout << l << ' ' << get(l);
}
Compilation message
burrow.cpp: In function 'int main()':
burrow.cpp:56:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = l + r >> 1;
~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
2 ms |
640 KB |
Output is correct |
6 |
Correct |
1 ms |
640 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
7 ms |
1152 KB |
Output is correct |
9 |
Correct |
11 ms |
2048 KB |
Output is correct |
10 |
Correct |
31 ms |
2048 KB |
Output is correct |
11 |
Correct |
57 ms |
2560 KB |
Output is correct |
12 |
Correct |
35 ms |
4352 KB |
Output is correct |
13 |
Correct |
41 ms |
1280 KB |
Output is correct |
14 |
Correct |
101 ms |
3584 KB |
Output is correct |
15 |
Correct |
101 ms |
3584 KB |
Output is correct |
16 |
Correct |
112 ms |
3576 KB |
Output is correct |
17 |
Correct |
136 ms |
4464 KB |
Output is correct |
18 |
Correct |
408 ms |
5248 KB |
Output is correct |
19 |
Correct |
473 ms |
6008 KB |
Output is correct |
20 |
Correct |
851 ms |
6820 KB |
Output is correct |
21 |
Correct |
931 ms |
7672 KB |
Output is correct |
22 |
Correct |
1223 ms |
8388 KB |
Output is correct |
23 |
Correct |
1219 ms |
8440 KB |
Output is correct |
24 |
Correct |
819 ms |
8056 KB |
Output is correct |
25 |
Correct |
1044 ms |
8312 KB |
Output is correct |