Submission #906120

#TimeUsernameProblemLanguageResultExecution timeMemory
906120JakobZorzQuality Of Living (IOI10_quality)C++17
80 / 100
5072 ms140116 KiB
#include"quality.h"
#include<iostream>
using namespace std;

int w2,h2,w,h;
int mat[3000][3000];

bool check(int val){
    for(int y=0;y<=h2-h;y++){
        int low=0;
        for(int x2=0;x2<w-1;x2++)
            for(int y2=y;y2<y+h;y2++)
                low+=(mat[x2][y2]<=val);
        
        for(int x=0;x<=w2-w;x++){
            
            if(x)
                for(int y2=y;y2<y+h;y2++)
                    low-=(mat[x-1][y2]<=val);
            for(int y2=y;y2<y+h;y2++)
                low+=(mat[x+w-1][y2]<=val);
            if(low>=(w*h+1)/2){
                //cout<<val<<" "<<low<<" "<<(w*h+1)/2<<" false\n";
                return true;
            }
        }
    }
    //cout<<val<<" true\n";
    return false;
}

int rectangle(int R,int C,int H,int W,int Q[3001][3001]){
    w2=R;
    h2=C;
    w=H;
    h=W;
    for(int x=0;x<w2;x++)
        for(int y=0;y<h2;y++)
            mat[x][y]=Q[x][y];
            
    int bl=0,br=w2*h2;
    while(bl<br-1){
        int mid=(bl+br)/2;
        if(check(mid))
            br=mid;
        else
            bl=mid;
    }
    
	return br;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...