# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
168404 | abil | Luxury burrow (IZhO13_burrow) | C++14 | 727 ms | 14072 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define fr first
#define sc second
#define pb push_bacak
#define mk make_pair
#define all(s) s.begin(),s.end()
//#define int long long
using namespace std;
const int N = (1e6 + 12);
const int mod = (1e9 + 7);
const int INF = (0x3f3f3f3f);
int a[1012][1012], b[1012], n, m, l[1012], r[1012];
int check(int x){
for(int i = 1;i <= m; i++){
b[i] = 0;
}
int res = 0;
stack <int > st;
for(int i = 1;i <= n; i++){
for(int j = 1;j <= m; j++){
if(a[i][j] >= x){
b[j]++;
}
else{
b[j] = 0;
}
}
for(int j = 1;j <= m; j++){
while(!st.empty() && b[st.top()] >= b[j]){
st.pop();
}
if(!st.empty()){
l[j] = st.top() + 1;
}
else{
l[j] = 1;
}
st.push(j);
}
while(!st.empty()){
st.pop();
}
for(int j = m;j >= 1; j--){
while(!st.empty() && b[st.top()] >= b[j]){
st.pop();
}
if(!st.empty()){
r[j] = st.top() - 1;
}
else{
r[j] = m;
}
st.push(j);
}
while(!st.empty()){
st.pop();
}
for(int j = 1;j <= m; j++){
res = max(res, (r[j] - l[j] + 1) * b[j]);
}
}
return res;
}
main()
{
int k;
scanf("%d%d%d", &n, &m, &k);
for(int i = 1;i <= n; i++){
for(int j = 1;j <= m; j++){
scanf("%d", &a[i][j]);
}
}
//cout << check(2);
int l = 0, r = INF;
while(r - l > 1){
int mid = (r + l) >> 1;
if(check(mid) >= k){
l = mid;
}
else{
r = mid;
}
}
if(check(r) >= k){
l = r;
}
printf("%d %d", l, check(l));
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |