# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
861098 | 2023-10-15T09:44:14 Z | biximo | Quality Of Living (IOI10_quality) | C++17 | 0 ms | 0 KB |
#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; }