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>
#define z exit(0)
using namespace std;
const int N = 3005;
int qs[N][N], a[N][N];
bool V(int i, int j, int m, int n){ return i>=0 && j>=0 && i<m && j<n;}
int f(int i, int j, int m, int n){ return V(i, j, m, n) ? qs[i][j] : 0;}
int rectangle(int m, int n, int kx, int ky, int a[3001][3001]){
int low = 0, high = 1e9, t, p = kx * ky;
while(low <= high){
int mid = low + ((high-low)>>1);
for(int i = 0; i<m; ++i) for(int j = 0; j<n; ++j) qs[i][j] = f(i-1, j, m, n) + f(i, j-1, m, n) + (a[i][j] <= mid) - f(i-1, j-1, m, n);
bool ch = false;
for(int i = kx-1; i<m; ++i){
for(int j = ky-1; j<n; ++j) if(qs[i][j] - f(i-kx, j, m, n) - f(i, j-ky, m, n) + f(i-kx, j-ky, m, n) > (p-1)/2){ch = true; break;}
if(ch) break;
}
if(ch) high = mid-1, t = mid;
else low = mid+1;
}
return t;
}
/*
signed main(){
int m, n, kx, ky; scanf("%d %d %d %d", &m, &n, &kx, &ky);
for(int i = 0; i<m; ++i){
for(int j = 0; j<n; ++j) scanf("%d", &a[i][j]);
}
printf("%d", rectangle(m, n, kx, ky, a));
}
*/
Compilation message (stderr)
quality.cpp: In function 'int rectangle(int, int, int, int, int (*)[3001])':
quality.cpp:21:9: warning: 't' may be used uninitialized in this function [-Wmaybe-uninitialized]
21 | return t;
| ^
# | 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... |