# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1009138 | Muaath_5 | 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 "quality.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 3003;
ll pref[N][N];
ll query(int x1, int y1, int x2, int y2) {
return pref[x2][y2] - pref[x2][y1-1] - pref[x1-1][y2] + pref[x1-1][y1-1];
}
int rectangle(int R, int C, int H, int W, int Q[3001][3001]) {
int l = 1, r = R*C;
while (l < r) {
const int mid = (l+r+1)/2;
for (int i = 1; i <= R; i++) {
for (int j = 1; j <= C; j++) {
pref[i][j] = Q[i-1][j-1] >= mid;
pref[i][j] += pref[i][j-1];
}
}
for (int i = 1; i <= R; i++) {
for (int j = 1; j <= C; j++) {
pref[i][j] += pref[i-1][j];
}
}
int sum = 0;
bool ok = false;
for (int i = 1; i <= R-H+1; i++) {
for (int j = 1; j <= C-W+1; j++) {
if (query(i, j, i+H-1, j+W-1) >= H*W/2 + (H*W%2)) {
ok = true;
}
}
}
if (ok)
l = mid;
else
r = mid-1;
}
return l;
}