#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define int long long
using namespace std;
const int N = 2e5 + 5;
main(){
int n, m, k;
cin >> n >> m >> k;
vector < vector <int> > v (n + 1, vector <int> (m + 1));
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
cin >> v[i][j];
}
}
int ans = 0;
auto check = [&](int x){
vector < vector <int> > p(n + 1, vector <int> (m + 1, 0));
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
if(v[i][j] >= x)
p[i][j] = 1 + p[i - 1][j];
}
}
ans = 0;
for(int i = 1; i <= n; i++){
deque <int> q;
for(int j = 1 ; j <= m; j++){
int ind = j;
while(!q.empty() && p[i][j] <= p[i][q.front()]){
ans = max(ans, p[i][q.front()] * (j - q.front()));
p[i][q.front()] = p[i][j];
ind = min(ind, q.front());
q.pop_front();
}
q.push_front(ind);
}
while(!q.empty()){
ans = max(((m + 1) - q.front()) * p[i][q.front()], ans);
q.pop_front();
}
}
return (ans >= k);
};
int l = 0, r = 1e9;
while(r - l > 1){
int mid = (l + r) >> 1;
if(check(mid)){
l = mid;
}else
r = mid;
}
check(l);
cout << l <<" " << ans;
}
Compilation message
burrow.cpp:13:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
13 | main(){
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
2 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
9 ms |
340 KB |
Output is correct |
9 |
Correct |
19 ms |
596 KB |
Output is correct |
10 |
Correct |
46 ms |
984 KB |
Output is correct |
11 |
Correct |
60 ms |
1276 KB |
Output is correct |
12 |
Correct |
44 ms |
1108 KB |
Output is correct |
13 |
Correct |
59 ms |
1140 KB |
Output is correct |
14 |
Correct |
147 ms |
2960 KB |
Output is correct |
15 |
Correct |
150 ms |
2848 KB |
Output is correct |
16 |
Correct |
154 ms |
2820 KB |
Output is correct |
17 |
Correct |
240 ms |
4216 KB |
Output is correct |
18 |
Correct |
313 ms |
5992 KB |
Output is correct |
19 |
Correct |
482 ms |
8104 KB |
Output is correct |
20 |
Correct |
634 ms |
10388 KB |
Output is correct |
21 |
Correct |
712 ms |
13076 KB |
Output is correct |
22 |
Correct |
1082 ms |
16168 KB |
Output is correct |
23 |
Correct |
869 ms |
16256 KB |
Output is correct |
24 |
Correct |
807 ms |
12232 KB |
Output is correct |
25 |
Correct |
1012 ms |
16284 KB |
Output is correct |