# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
893893 | Irate | Quality Of Living (IOI10_quality) | C++14 | 0 ms | 0 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.
#include<bits/stdc++.h>
using namespace std;
vector<vector<int>>grid;
bool check(vector<vector<int>>&pref, int R, int C, int H, int W){
for(int i = 1;i <= R;++i){
for(int j = 1;j <= C;++j){
if(i + H - 1 <= R && j + W - 1 <= C){
int num = pref[i + H - 1][j + W - 1] - pref[i - 1][j + W - 1] - pref[i + H - 1][j - 1] + pref[i - 1][j - 1];
if(num >= H * W / 2 + 1)return true;
}
}
}
return false;
}
int rectangle(int R, int C, int H, int W, vector<vector<int>>&Q){
grid.assign(R + 1, vector<int>(C + 1));
for(int i = 1;i <= R;++i){
for(int j = 1;j <= C;++j){
grid[i][j] = Q[i - 1][j - 1];
}
}
int l = 1, r = R * C, ans = r;
while(l <= r){
int mid = (l + r) >> 1;
vector<vector<int>>pref(R + 1, vector<int>(C + 1));
for(int i = 1;i <= R;++i){
for(int j = 1;j <= C;++j){
if(grid[i][j] <= mid){
pref[i][j]++;
}
pref[i][j] += pref[i - 1][j] + pref[i][j - 1] - pref[i - 1][j - 1];
}
}
if(check(pref, R, C, H, W)){
ans = mid;
r = mid - 1;
}
else{
l = mid + 1;
}
}
return ans;
}
// int main(){
// ios_base::sync_with_stdio(0);
// cin.tie(0);
// int n, m, H, W;
// cin >> n >> m >> H >> W;
// vector<vector<int>>v(n, vector<int>(m));
// for(int i = 0;i < n;++i){
// for(int j = 0;j < m;++j){
// cin >> v[i][j];
// }
// }
// cout << rectangle(n, m, H, W, v);
// }