# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1101068 | SulA | 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 <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define bitcount __builtin_popcountll
using namespace std;
using namespace __gnu_pbds;
using namespace chrono;
int rectangle(int n, int m, int h, int w, vector<vector<int>> a) {
auto check = [&](int x) {
vector<vector<int>> g(n, vector<int>(m, 0));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
g[i][j] = a[i][j] <= x ? 1 : -1;
if (i != 0) g[i][j] += g[i-1][j];
if (j != 0) g[i][j] += g[i][j-1];
if (i != 0 && j != 0) g[i][j] -= g[i-1][j-1];
}
}
auto sum = [&](int x1, int y1, int x2, int y2) {
int sum = g[x2][y2];
if (x1 != 0) sum -= g[x1 - 1][y2];
if (y1 != 0) sum -= g[x2][y1 - 1];
if (x1 != 0 && y1 != 0) sum += g[x1 - 1][y1 - 1];
return sum;
};
int mx = -h*w;
for (int x1 = 0, x2 = h-1; x2 < n; x1++, x2++) {
for (int y1 = 0, y2 = w-1; y2 < m; y1++, y2++) {
int s = sum(x1, y1, x2, y2);
mx = max(mx, s);
}
}
return mx;
};
int ans = 0;
int l = 1, r = n*m;
for (int i = l; i <= r; i++) if (check(i) > 0) return i;
assert(false);
}