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"
typedef long long ll;
ll r, c, h, w;
ll a[3005][3005];
ll b[3005][3005];
bool f(ll p)
{
for(ll i = 1; i <= r; i++)
{
for(ll j = 1; j <= c; j++)
{
if(a[i][j] <= p) b[i][j] = 1;
else b[i][j] = 0;
b[i][j] += b[i - 1][j] + b[i][j - 1] - b[i - 1][j - 1];
}
}
for(ll i = h; i <= r; i++)
{
for(ll j = w; j <= c; j++)
{
ll t = b[i][j] - b[i - h][j] - b[i][j - w] + b[i - h][j - w];
if(t >= (h * w + 1) / 2) return true;
}
}
return false;
}
int rectangle(int R, int C, int H, int W, int Q[3001][3001]) {
r = R;
c = C;
h = H;
w = W;
for(ll i = 0; i < r; i++)
{
for(ll j = 0; j < c; j++)
{
a[i + 1][j + 1] = Q[i][j];
}
}
ll lt = 0, rt = r * c, mid, ans = 0;
while(lt <= rt)
{
mid = (lt + rt) / 2;
if(f(mid)) ans = mid, rt = mid - 1;
else lt = mid + 1;
}
return ans;
}
# | 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... |