# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
349641 | eric00513 | Quality Of Living (IOI10_quality) | C++98 | 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 MAX = 3003;
int a[MAX][MAX], r, c, h, w;
int t[MAX][MAX], pfx[MAX][MAX];
int getval(int x) { return x ? x / abs(x) : 0; }
int check(int x)
{
int i, j;
for (i = 1; i <= r; i++)
for (j = 1; j <= c; j++)
t[i][j] = getval(a[i][j]);
for (i = 1; i <= r; i++)
for (j = 1; j <= c; j++)
pfx[i][j] = pfx[i - 1][j] + pfx[i][j - 1] - pfx[i - 1][j - 1] + t[i][j];
for (i = 1; i <= r - (h - 1); i++)
for (j = 1; j <= c - (w - 1); j++)
{
int ki = i + h - 1, kj = j + w - 1;
int val = pfx[ki][kj] - pfx[ki][j - 1] - pfx[i - 1][kj] + pfx[i - 1][j - 1];
if (val == 0)
return 0;
else if (val < 0)
return -1;
}
return 1;
}
int main(void)
{
int i, j;
scanf("%d %d %d %d", &r, &c, &h, &w);
for (i = 1; i <= r; i++)
for (j = 1; j <= c; j++)
scanf("%d", &a[i][j]);
int lo = 1, hi = r * c, mid;
while (true)
{
mid = (lo + hi) / 2;
int res = check(mid);
if (res == 0)
break;
if (res == 1)
lo = mid + 1;
else
hi = mid - 1;
}
printf("%d", mid);
return 0;
}