# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
390175 | MilosMilutinovic | Quality Of Living (IOI10_quality) | C++14 | 3467 ms | 175372 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.
/**
* author: milos
* created: 15.04.2021 12:47:15
**/
#include <bits/stdc++.h>
#include "quality.h"
using namespace std;
int rectangle(int R, int C, int H, int W, int Q[3001][3001]) {
vector<int> xs;
for (int i = 0; i < R; i++) {
for (int j = 0; j < C; j++) {
xs.push_back(Q[i][j]);
}
}
auto InRect = [&](int x1, int x2, int y1, int y2, int x, int y) {
return x1 <= x && x <= x2 && y1 <= y && y <= y2;
};
auto Can = [&](int val) {
int sum[R][C];
for (int i = 0; i < R; i++) {
for (int j = 0; j < C; j++) {
sum[i][j] = (Q[i][j] <= val ? 1 : 0);
if (i > 0) sum[i][j] += sum[i - 1][j];
if (j > 0) sum[i][j] += sum[i][j - 1];
if (i > 0 && j > 0) sum[i][j] -= sum[i - 1][j - 1];
}
}
int x = -1, y = -1;
for (int i = 0; i < R; i++) {
for (int j = 0; j < C; j++) {
if (Q[i][j] == val) {
x = i; y = j;
}
}
}
assert(x != -1 && y != -1);
int P = H * W;
for (int i = 0; i < R; i++) {
for (int j = 0; j < C; j++) {
int ii = i + H - 1, jj = j + W - 1;
if (ii >= R || jj >= C) {
continue;
}
int cnt = sum[ii][jj];
if (i > 0) cnt -= sum[i - 1][jj];
if (j > 0) cnt -= sum[ii][j - 1];
if (i > 0 && j > 0) cnt += sum[i - 1][j - 1];
if (cnt >= P / 2 + 1) {
return true;
}
}
}
return false;
};
sort(xs.begin(), xs.end());
xs.erase(unique(xs.begin(), xs.end()), xs.end());
int bot = 0, top = (int) xs.size() - 1, ans = 1e9;
while (bot <= top) {
int mid = bot + top >> 1;
if (Can(xs[mid])) {
ans = xs[mid];
top = mid - 1;
} else {
bot = mid + 1;
}
}
return ans;
}
Compilation message (stderr)
# | 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... |