# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
332097 | Sho10 | 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> //Andrei Alexandru a.k.a Sho10
#include "quality.h"
#define ll long long
#define double long double
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000007
#define PI 3.14159265359
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005ll
#define CODE_START ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
int a[3005][3005],pref[3005][3005],n,m,h,w;
int sum(int x2,int y2){
int x1=x2-h+1;
int y1=y2-w+1;
return pref[x2][y2]-pref[x2][y1-1]-pref[x1-1][y2]+pref[x1-1][y1-1];
}
int check(int x){
for(int i=1;i<=n;i++)
{
int nr=0;
for(int j=1;j<=m;j++)
{
if(a[i][j]<=x){
nr++;
}
pref[i][j]=pref[i-1][j]+nr;
}
}
int mn=(h*w+1)/2;
for(int i=h;i<=n;i++)
{
for(int j=w;j<=m;j++)
{
if(sum(i,j)>=mn){
return 1;
}
}
}
return 0;
}
int rectangle(int R,int C,int H,int W,int Q[3005][3005]){
n=R;
m=C;
h=H;
w=W;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
a[i][j]=Q[i-1][j-1];
}
}
int l=1,r=n*m;
while(l<r){
int mid=(l+r)/2;
if(check(mid)){
r=mid;
}else l=mid+1;
}
return l;
}
/*
int32_t main(){
CODE_START;
*/