답안 #390741

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
390741 2021-04-16T19:54:15 Z Sorting 삶의 질 (IOI10_quality) C++17
0 / 100
1 ms 588 KB
#include "quality.h"
#include <bits/stdc++.h>
#pragma GCC optmize("O3")

using namespace std;

const int N = 3000 + 3;

int q[N][N];
int r, c, h, w;
int a[N][N];

int query(int x1, int y1, int x2, int y2){
    return a[x2][y2] - a[x1 - 1][y2] - a[x2][y1 - 1] + a[x1 - 1][y1 - 1];
}

bool check(int mid){
    for(int i = 1; i <= r; ++i)
        fill(a[i] + 1, a[i] + 1 + c, 0);

    for(int i = 1; i <= r; ++i)
        for(int j = 1; j <= c; ++j)
            a[i][j] = a[i][j - 1] + a[i - 1][j] - a[i - 1][j - 1] + (q[i][j] <= mid);

    for(int i = 1; i <= r - h + 1; ++i)
        for(int j = 1; j <= c - w + 1; ++j)
            if(query(i, j, i + h - 1, j + w - 1) >= h * w / 2 + 1)
                return true;
    return false;
}

int rectangle(int _r, int _c, int _h, int _w, int _q[3001][3001]) {
    r = _r, c = _c, h = _h, w = _w;
    for(int i = 1; i <= r; ++i)
        for(int j = 1; j <= c; ++j)
            q[i][j] = q[i - 1][j - 1];

    int l_bs = 1, r_bs = r * c;
    while(l_bs != r_bs){
        int mid = (l_bs + r_bs) >> 1;
        if(check(mid)) r_bs = mid;
        else l_bs = mid + 1;
    }
    return l_bs;
}
/*
5 5 3 3
5 11 12 16 25
17 18 2 7 10
4 23 20 3 1
24 21 19 14 9
6 22 8 13 15
*/

Compilation message

quality.cpp:3: warning: ignoring #pragma GCC optmize [-Wunknown-pragmas]
    3 | #pragma GCC optmize("O3")
      |
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 588 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 588 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 588 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 588 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 588 KB Output isn't correct
2 Halted 0 ms 0 KB -