# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1085032 | Sunbae | Quality Of Living (IOI10_quality) | C++17 | 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>
#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[][N]){
int low = 0, high = 1e9, ans;
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) > (kx*ky-1)/2){ch = true; break;}
if(ch) break;
}
if(ch) high = mid-1, ans = mid;
else low = mid+1;
}
return ans;
}
/*
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));
}
*/