# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
208883 | DodgeBallMan | Quality Of Living (IOI10_quality) | C++14 | 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 "quality.h"
#include <bits/stdc++.h>
#define pii pair<int, int>
#define x first
#define y second
using namespace std;
const int N = 3e3+5;
int sum[N][N], n, c, r, h, w;
pii pos[N*N];
bool chk( int mid, int rec[][] ) {
memset( sum, 0, sizeof sum );
for( int i = mid + 1 ; i <= n ; i++ ) sum[pos[i].x][pos[i].y]++;
for( int i = 1 ; i <= r ; i++ )
for( int j = 1 ; j <= c ; j++ )
sum[i][j] += sum[i-1][j] + sum[i][j-1] - sum[i-1][j-1];
for( int i = h ; i <= r ; i++ )
for( int j = w ; j <= c ; j++ )
if( sum[i][j] - sum[i-h][j] - sum[i][j-w] + sum[i-h][j-w] <= h * w / 2 ) return true;
return false;
}
int rectangle( int R, int C, int H, int W, int rec[][] ) {
r = R, c = C, w = W, h = H;
n = r*c;
for( int i = 0 ; i < r ; i++ ) for( int j = 0 ; j < c ; j++ ) pos[rec[i][j]] = pii( i+1, j+1 );
int l = 1, r = n;
while( l < r ) {
int mid = l + r + 1 >> 1;
if( chk( mid, rec ) ) l = m;
else r = m - 1;
}
return l;
}