# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
861098 | biximo | 삶의 질 (IOI10_quality) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int r, c, h, w;
int grid[3005][3005], pref[3005][3005];
int query(int x1, int y1) {
int x2 = x1 + h - 1, y2 = y1 + w - 1;
return pref[x2][y2] + pref[x1 - 1][y1 - 1] - pref[x1 - 1][y2] - pref[x2][y1 - 1];
}
bool check(int m) {
for(auto&i: pref) for(auto&j: i) j = 0;
// cout << m << "\n";
for(int i = 1; i <= r; i ++) {
for(int j = 1; j <= c; j ++) {
pref[i][j] = (grid[i][j] <= m) + pref[i][j - 1] + pref[i - 1][j] - pref[i - 1][j - 1];
// cout << pref[i][j] << " ";
}
// cout << "\n";
}
// cout << "\n";
for(int i = 1; i <= c - h + 1; i ++) {
for(int j = 1; j <= (c - w + 1); j ++) {
if(query(i, j) * 2 >= h * w) return true;
}
}
return false;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> r >> c >> h >> w;
for(int i = 1; i <= r; i ++) for(int j = 1; j <= c; j ++) {
cin >> grid[i][j];
}
int low = 1, high = r * c, ans;
while(low <= high) {
int mid = (low + high) >> 1;
if(check(mid)) {
high = mid - 1;
ans = mid;
} else {
low = mid + 1;
}
}
cout << ans;
}