# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
645694 | asdfghjkl | 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>
#include<vector>
using namespace std;
bool binar (vector<vector<int>> A, vector<vector<int>> B, int R, int C, int H, int W, int k);
int main () {
int R, C, H, W, k, mn=1;
cin>>R>>C>>H>>W;
int mx=R*C;
vector<vector<int>> A(R, vector<int>(C));
vector<vector<int>> B(R, vector<int>(C));
for (int i=0; i<R; i++)
{
for (int o=0; o<C; o++)
{
cin>>A[i][o];
}
}
while (mn!=mx)
{
k=(mx+mn)/2;
if (binar (A,B,R,C,H,W,k)==1) mx=k-1;
else mn=k+1;
}
cout<<mn;
return 0;
};
bool binar (vector<vector<int>> A, vector<vector<int>> B, int R, int C, int H, int W, int k)
{
bool x=0;
bool pref[R][C];
for (int i=0; i<R; i++)
{
for (int o=0; o<C; o++)
{
if (A[i][o]<k) B[i][o]=1;
else B[i][o]=0;
if (i==0&&o==0) pref [i][o]=B[i][o];
else if (i==0&&o>0) pref [i][o]=B[i][o]+pref[i][o-1];
else if (i>0&&o==0) pref [i][o]=B[i][o]+pref[i-1][o];
else pref[i][o]=pref[i-1][o]+pref[i][o-1]-pref[i-1][o-1]+B[i][o];
}
}
for (int i=0; i<R-H; i++)
{
for (int o=0; o<C-W; o++)
{
if ((pref[i+H][o+W]-pref[i-1][o+W]-pref[i+H][o-1]+pref[i-1][o-1])>=(H*W)/2) x=1;
}
}
return x;
}