# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
853650 | vjudge1 | 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<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int r, c, h, w, a[3010][3010], s[3010][3010];
bool check(int x)
{
for(int i = 1; i <= r; i++)
{
for(int j = 1; j <= c; j++)
{
s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + (a[i][j] > x);
}
}
for(int i = h; i <= r; i++)
{
for(int j = w; j <= c; j++)
{
if(s[i][j] - s[i - h][j] - s[i][j - w] + s[i - h][j - w] <= h * w / 2)
return true;
}
}
return false;
}
int main()
{
scanf("%d%d%d%d", &r, &c, &h, &w);
for(int i = 1; i <= r; i++)
{
for(int j = 1; j <= c; j++)
{
scanf("%d", &a[i][j]);
}
}
int L = h * w / 2 + 1, R = r * c;
while(L < R)
{
int mid = (L + R) >> 1;
if(check(mid)) R = mid;
else L = mid + 1;
}
printf("%d", L);
return 0;
}