제출 #295656

#제출 시각아이디문제언어결과실행 시간메모리
295656mat_v삶의 질 (IOI10_quality)C++14
100 / 100
3173 ms210972 KiB
#include "quality.h"

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
#define mod 998244353
#define xx first
#define yy second
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define ll long long
#define pii pair<int,int>


using namespace std;
using namespace __gnu_pbds;
typedef tree<pii, null_type, less<pii>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;/// find_by_order(x)(x+1th) , order_of_key() (strictly less)
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());


int n,m,h,w;

int mat[3005][3005];
int pref[3005][3005][2];

int get(int a, int b, int c, int d, int idx){
    int ans = 0;
    ans += pref[c][d][idx];
    ans += pref[a - 1][b - 1][idx];
    ans -= pref[a - 1][d][idx];
    ans -= pref[c][b - 1][idx];
    return ans;
}


bool check(int x){
    ff(i,1,n){
        ff(j,1,m){
            ff(k,0,1)pref[i][j][k] = pref[i - 1][j][k] + pref[i][j - 1][k] - pref[i - 1][j - 1][k];
            if(mat[i][j] <= x)pref[i][j][0]++;
            else if(mat[i][j] > x)pref[i][j][1]++;
        }
    }

    ff(i,1,n - h + 1){
        ff(j,1,m - w + 1){
            bool los = 0;
            ff(k,0,0){
                int sta = get(i,j,i+h-1,j+w-1,k);
                int kol = h*w;
                if(sta >= (kol + 1)/2)return 1;
            }
        }
    }
    return 0;
}

int rectangle(int R, int C, int H, int W, int Q[3001][3001]) {
    n = R;
    m = C;
    h = H;
    w = W;
    ff(i,0,n - 1){
        ff(j,0,m - 1){
            mat[i + 1][j + 1] = Q[i][j];
        }
    }
    int l = 1;
    int r = n*m;

    while(l < r){
        int mid = (l + r) / 2;
        if(check(mid)){
            r = mid;
        }
        else l = mid + 1;
    }
    return l;
}



컴파일 시 표준 에러 (stderr) 메시지

quality.cpp: In function 'bool check(int)':
quality.cpp:8:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    8 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
quality.cpp:41:5: note: in expansion of macro 'ff'
   41 |     ff(i,1,n){
      |     ^~
quality.cpp:8:27: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
    8 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
quality.cpp:42:9: note: in expansion of macro 'ff'
   42 |         ff(j,1,m){
      |         ^~
quality.cpp:8:27: warning: unnecessary parentheses in declaration of 'k' [-Wparentheses]
    8 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
quality.cpp:43:13: note: in expansion of macro 'ff'
   43 |             ff(k,0,1)pref[i][j][k] = pref[i - 1][j][k] + pref[i][j - 1][k] - pref[i - 1][j - 1][k];
      |             ^~
quality.cpp:8:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    8 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
quality.cpp:49:5: note: in expansion of macro 'ff'
   49 |     ff(i,1,n - h + 1){
      |     ^~
quality.cpp:8:27: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
    8 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
quality.cpp:50:9: note: in expansion of macro 'ff'
   50 |         ff(j,1,m - w + 1){
      |         ^~
quality.cpp:8:27: warning: unnecessary parentheses in declaration of 'k' [-Wparentheses]
    8 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
quality.cpp:52:13: note: in expansion of macro 'ff'
   52 |             ff(k,0,0){
      |             ^~
quality.cpp:51:18: warning: unused variable 'los' [-Wunused-variable]
   51 |             bool los = 0;
      |                  ^~~
quality.cpp: In function 'int rectangle(int, int, int, int, int (*)[3001])':
quality.cpp:8:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    8 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
quality.cpp:67:5: note: in expansion of macro 'ff'
   67 |     ff(i,0,n - 1){
      |     ^~
quality.cpp:8:27: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
    8 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
quality.cpp:68:9: note: in expansion of macro 'ff'
   68 |         ff(j,0,m - 1){
      |         ^~
#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...