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"quality.h"
#include<iostream>
#include<vector>
using namespace std;
int w2,h2,w,h;
int mat[3000][3000];
bool check(int val){
vector<int>cols(w2);
int cube=0;
for(int y=0;y<=h2-h;y++){
if(y==0){
for(int x2=0;x2<w-1;x2++)
for(int y2=0;y2<h;y2++)
cube+=(mat[x2][y2]<=val);
for(int x=0;x<w2;x++)
for(int y2=0;y2<h;y2++)
cols[x]+=(mat[x][y2]<=val);
}else{
for(int x2=0;x2<w-1;x2++){
cube-=(mat[x2][y-1]<=val);
cube+=(mat[x2][y+h-1]<=val);
}
for(int x=0;x<w2;x++){
cols[x]-=(mat[x][y-1]<=val);
cols[x]+=(mat[x][y+h-1]<=val);
}
}
int low=cube;
for(int x=0;x<=w2-w;x++){
if(x)
low-=cols[x-1];
low+=cols[x+w-1];
if(low>=(w*h+1)/2){
return true;
}
}
}
return false;
}
int rectangle(int R,int C,int H,int W,int Q[3001][3001]){
w2=R;
h2=C;
w=H;
h=W;
for(int x=0;x<w2;x++)
for(int y=0;y<h2;y++)
mat[x][y]=Q[x][y];
int bl=0,br=w2*h2;
while(bl<br-1){
int mid=(bl+br)/2;
if(check(mid))
br=mid;
else
bl=mid;
}
return br;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |