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"
#include <bits/stdc++.h>
#define ar array
#define ll long long
int n, m, h, w;
const int N = 3005;
int A[N][N];
int B[N][N];
int query(int x1, int y1, int x2, int y2){
int res = B[x2][y2];
if(x1)res -= B[x1-1][y2];
if(y1)res -= B[x2][y1-1];
if(x1 && y1)res += B[x1-1][y1-1];
return res;
}
bool check(int k){
for(int i = 0;i<n;i++){
for(int j = 0;j<m;j++){
B[i][j] = (A[i][j] <= k);
}
}
for(int i = 1;i<n;i++){
for(int j = 1;j<m;j++){
B[i][j] += B[i-1][j];
B[i][j] += B[i][j-1];
B[i][j] -= B[i-1][j-1];
}
}
for(int i = 0;i + h - 1 < n;i++){
for(int j = 0;j + w - 1 < m;j++){
if(query(i, j, i + h - 1, j + w - 1) >= (w * h) / 2 + 1)return 1;
}
}
return 0;
}
int rectangle(int R, int C, int H, int W, int Q[3001][3001]) {
n = R;
m = C;
h = H;
w = W;
for(int i = 0;i<n;i++){
for(int j = 0;j<m;j++){
A[i][j] = Q[i][j];
}
}
int lo = 1;
int hi = n * m -1 ;
int ans = -1;
while(lo <= hi){
int mid = (lo + hi) / 2;
if(check(mid)){
ans = mid;
hi = mid - 1;
}else lo = 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... |