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"
using namespace std;
#define endl '\n'
#define ll long long
#define all(x) x.begin(), x.end()
int h, w, r, c, a[3002][3002], dp[3002][3002];
bool b(int v) {
int s = (h * w) / 2 + 1;
for (int i = 0; i < r; i++) {
int cnt = 0;
for (int j = 0; j < c; j++) {
if (a[i][j] <= v) cnt++;
dp[i][j] = cnt;
if (i - 1 >= 0) {
dp[i][j] += dp[i - 1][j];
}
if (i == h - 1 && j == w - 1) {
if (dp[i][j] >= s) return 1;
}
else if (i == h - 1 && j >= w) {
if (dp[i][j] - dp[i][j - w] >= s) return 1;
}
else if (i >= h && j == w - 1) {
if (dp[i][j] - dp[i - h][j] >= s) return 1;
}
else if (i >= h - 1 && j >= w - 1) {
if (dp[i][j] - dp[i - h][j] - dp[i][j - w] + dp[i - h][j - w] >= s) return 1;
}
}
}
return 0;
}
int rectangle(int R, int C, int H, int W, int Q[3001][3001]) {
r = R, c = C, h = H, w = W;
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
a[i][j] = Q[i][j];
}
}
vector<int> v;
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
cin >> a[i][j];
v.push_back(a[i][j]);
}
}
int l = 0, rr = r * c;
sort(all(v));
int ans = INT_MAX;
while (l + 1 < rr) {
int m = (l + rr) / 2;
if (b(v[m])) {
ans = min(ans, v[m]);
rr = m;
}
else {
l = m;
}
}
if (b(v[0])) ans = v[0];
return ans;
}
# | 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... |