Submission #990456

#TimeUsernameProblemLanguageResultExecution timeMemory
990456aaaaaarrozQuality Of Living (IOI10_quality)C++17
100 / 100
971 ms210908 KiB
    #include <bits/stdc++.h>
    #include "quality.h"
    using namespace std;
     
    const int maxn = 3e3 + 1;
    vector<vector<int>> v( maxn, vector<int>(maxn)), s1( maxn, vector<int>(maxn)), s2( maxn, vector<int>(maxn));
     
    bool check( int n, int m, int h, int w, int k ){
      for( int i = 1; i <= n; i++ ) for( int j = 1; j <= m; j++ ){
        s1[i][j] = ((v[i][j] < k) ? 1 : 0 ) + s1[i - 1][j] + s1[i][j - 1] - s1[i - 1][j - 1];
        if( i >= h && j >= w ){
          int v1 = s1[i][j] - s1[i - h][j] - s1[i][j - w] + s1[i - h][j - w];
          if( v1 >= (h*w + 1)/2 ) return true;
        }
      }
      return false;
    }
     
    int bs( int n, int m, int h, int w ){
      int l = 1, r = n*m;
      while( l < r ){
        int mid = ( l + r )/2;
        if( check(n, m, h, w, mid) ) r = mid;
        else l = mid + 1;
      }
      return r - 1;
    }
     
    int rectangle( int n, int m, int h, int w, int q[maxn][maxn] ){
      for( int i = 1; i <= n; i++ ) for( int j = 1; j <= m; j++ ) v[i][j] = q[i - 1][j - 1];
      return bs(n, m, h, w);
    }
#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...