# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
777424 | Petrix | Quality Of Living (IOI10_quality) | C++17 | 0 ms | 0 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 "grader.h"
#include <bits/stdc++.h>
using namespace std;
int rectangle(int r,int c,int h,int w,int q[3001][3001]){
int sm[3001][3001],bi[3001][3001],v[3001][3001],st,dr,mij;
for(i=1;i<=r;i++){
for(j=1;j<=c;j++){
v[i][j]=q[i-1][j-1];
}
}
st=0;dr=r*c;ans=r*c;
while(st<dr){
int s,b;
mij=(st+dr)/2;
bool adv=0;
for(i=1;i<=r;i++){
s=0;b=0;
for(j=1;j<=c;j++){
sm[i][j]=sm[i-1][j]+s;
if(v[i][j]<mij){
sm[i][j]++;s++;
}
bi[i][j]=bi[i-1][j]+b;
if(v[i][j]>mij){
bi[i][j]++;b++;
}
}
}
for(i=1;i<=r-h+1;i++){
for(j=0;j<c-w+1;j++){
s=sm[i+h-1][j+w-1]-sm[i+h-1][j-1]-sm[i-1][j+w-1]+sm[i-1][j-1];
b=bi[i+h-1][j+w-1]-bi[i+h-1][j-1]-bi[i-1][j+w-1]+bi[i-1][j-1];
int n=r*c;
if(s==b && s<=n/2 && n<=n/2)
ans=min(ans,mij);
if(s>=b)
adv=1;
}
}
if(adv==0)
st=mij+1;
else
dr=mij-1;
}
return ans;
}