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"
#include "grader.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, int a[3001][3001]) {
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 > 0;
};
int ans = 0;
int l = 1, r = n*m;
while (r > l) {
int mid = (l+r)/2;
if (check(mid)) r = mid;
else l = mid + 1;
}
return l;
assert(false);
}
Compilation message (stderr)
quality.cpp: In function 'int rectangle(int, int, int, int, int (*)[3001])':
quality.cpp:39:9: warning: unused variable 'ans' [-Wunused-variable]
39 | int ans = 0;
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |