# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
950875 | Yell0 | 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 <bits/stdc++.h>
using namespace std;
const int MN=3002;
int pfs[MN][MN], q[MN][MN];
int qry(int r1, int c1, int r2, int c2) {
int ans = pfs[r2][c2];
if(r1 > 0) ans -= pfs[r1-1][c2];
if(c1 > 0) ans -= pfs[r2][c1-1];
if(r1 > 0 && c1 > 0) ans += pfs[r1-1][c1-1];
return ans;
}
int rectangle(int R, int C, int H, int W, int Q[MN][MN]) {
int l = 1, h = R*C, target = H*W/2, ans;
while(l <= h) {
int X = (l+h)/2;
bool chk = 0;
for(int r=0; r<R; ++r) {
for(int c=0; c<C; ++c) {
pfs[r][c] = Q[r][c] <= X;
if(r > 0) pfs[r][c] += pfs[r-1][c];
if(c > 0) pfs[r][c] += pfs[r][c-1];
if(r > 0 && c > 0) pfs[r][c] -= pfs[r-1][c-1];
}
}
for(int r=0; r+H-1<R; ++r) {
for(int c=0; c+W-1<C; ++c) {
if(qry(r, c, r+H-1, c+W-1) > target) {
chk = 1;
}
}
}
if(chk) {
h = X-1;
ans = X;
} else l = X+1;
}
return ans;
}