이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#define FOR(var,bound) for(int var = 0; var < bound; var++)
#define FORB(var,lb,ub) for (int var = lb; var < ub; var++)
#define FORR(var,bound) for(int var = bound-1; var >= 0; var--)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;
int p[3001][3001];
int rectangle(int R, int C, int H, int W, int Q[3001][3001]) {
int l = 1;
int r = R * C + 1;
int target = (H * W + 1) / 2;
while (l != r - 1) {
int mid = (l + r) / 2 + 1;
for (int i = 0; i < R; i++) {
for (int j = 0; j < C; j++) {
p[i+1][j+1] = (Q[i][j] <= mid) + p[i][j+1] + p[i+1][j] - p[i][j];
}
}
bool valid = false;
for (int i = 0; i + H <= R && !valid; i++) {
for (int j = 0; j + W <= C; j++) {
if (p[i+H][j+W] - p[i+H][j] - p[i][j+W] + p[i][j] >= target) {
valid = true;
break;
}
}
}
if (valid) {
l = mid;
} else {
r = mid;
}
}
return l;
}
#ifdef LOCAL_TEST
int grid[3001][3001];
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
freopen("quality.in", "r", stdin);
int r, c, h, w;
cin >> r >> c >> h >> w;
FOR(i, r) {
FOR(j, c) {
cin >> grid[i][j];
}
}
cout << rectangle(r, c, h, w, grid) << endl;
}
#endif
# | 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... |