# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
512659 | lovro_nidogon1 | 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<bits/stdc++.h>
#include<quality.h>
#define breturn return
using namespace std;
int mat[3001][3001], r, c, h, w;
int sus[3001][3001], lo = 0, hi = 1e9, mid, exsus[3001][3001];
bool fun() {
for(int i = 0; i < r; i++) for(int j = 0; j < c; j++) {
if(mat[i][j] > mid) sus[i][j] = -1;
else if(mat[i][j] < mid) sus[i][j] = 1;
else sus[i][j] = 0;
}
for(int i = 0; i < r; i++) for(int j = 0; j < c; j++) {
exsus[i][j] = sus[i][j];
if(i and j) exsus[i][j] += exsus[i - 1][j] + exsus[i][j - 1] - exsus[i - 1][j - 1];
else if(i) exsus[i][j] += exsus[i - 1][j];
else if(j) exsus[i][j] += exsus[i][j - 1];
}
for(int i = h - 1; i < r; i++) for(int j = w - 1; j < c; j++) {
int sum = exsus[i][j];
if(i - h >= 0 and j - w >= 0) sum -= exsus[i - h][j] + exsus[i][j - w] - exsus[i - h][j - w];
else if(i - h >= 0 ) sum -= exsus[i - h][j];
else if(j - w >= 0) sum -= exsus[i][j - w];
if(sum >= 0) {
breturn true;
}
}
breturn false;
}
int rectangle(int R, int C, int H, int W, int Q[3001][3001]) {
mat = Q;
r = R;
c = C;
h = H;
w = W;
for(int i = 0; i < r; i++) for(int j = 0; j < c; j++) cin >> mat[i][j];
while(hi != lo) {
mid = (hi + lo)/2;
if(fun()) hi = mid;
else lo = mid + 1;
}
breturn hi;
}