# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
958113 | hyakup | 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>
#include "quality.h"
using namespace std;
const int maxn = 3e3 + 10;
vector<vector<int>> v( maxn, vector<int>(maxn)), s1( maxn, vector<int>(maxn)), s2( maxn, vector<int>(maxn));
bool check( int n, int m, int h, int w, int k ){
for( int i = 1; i <= n; i++ ) for( int j = 1; j <= m; j++ ){
s1[i][j] = ((v[i][j] < k) ? 1 : 0 ) + s1[i - 1][j] + s1[i][j - 1] - s1[i - 1][j - 1];
if( i >= h && j >= w ){
int v1 = s1[i][j] - s1[i - h][j] - s1[i][j - w] + s1[i - h][j - w];
if( v1 >= (h*w + 1)/2 ) return true;
}
}
return false;
}
int bs( int n, int m, int h, int w ){
int l = 1, r = n*m;
while( l < r ){
int mid = ( l + r )/2;
if( check(n, m, h, w, mid) ) r = mid;
else l = mid + 1;
}
return r - 1;
}
int rectangle( int n, int m, int h, int w, int q[maxn][maxn] ){
for( int i = 1; i <= n; i++ ) for( int j = 1; j <= m; j++ ) v[i][j] = q[i - 1][j - 1];
return bs(n, m, h, w);
}
// int q[maxn][maxn];
//
// int main(){
// int n, m, h, w; cin >> n >> m >> h >> w;
// for( int i = 0; i < n; i++ ) for( int j = 0; j < m; j++ ) cin >> q[i][j];
// cout << rectangle( n, m, h, w, q );
// }