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>
#include "quality.h"
#define ll long long
#define ld long double
#define vl vector<ll>
#define vi vector<int>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define f first
#define s second
#define pb push_back
#define p_b pop_back
using namespace std;
int rectangle(int R, int C, int H, int W, int Q[3001][3001]) {
int l = 1, r = R * C, ans = R * C;
int grid[3001][3001];
for(int i = 0; i < 3001; i++)
{
for(int j = 0; j < 3001; j++)
grid[i][j] = 0;
}
while(l <= r)
{
int mid = (l + r) / 2, maxx = 0;
for(int i = 0; i < R; i++)
{
for(int j = 0; j < C; j++)
{
int sum = 0;
grid[i][j] = (Q[i][j] <= mid);
if(i)
grid[i][j] += grid[i-1][j];
if(j)
grid[i][j] += grid[i][j-1];
if(i && j)
grid[i][j] -= grid[i-1][j-1];
if(R >= H - 1 && C >= W - 1){
sum = grid[i][j];
if(i - H >= 0)
sum -= grid[i-H][j];
if(j - W >= 0)
sum -= grid[i][j-W];
if(i - H >= 0 && j - W >= 0)
sum += grid[i-H][j-W];
maxx = max(maxx, sum);
}
}
}
if(maxx > R * C / 2)
{
ans = min(ans, mid);
r = mid - 1;
}
else
l = 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... |