답안 #897008

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
897008 2024-01-02T12:17:02 Z borisAngelov 호화 벙커 (IZhO13_burrow) C++17
100 / 100
461 ms 14044 KB
#include <bits/stdc++.h>

using namespace std;

const int maxn = 1005;
const int inf = 1e9 + 7;

int n, m, k;

int a[maxn][maxn];
int minHeight = inf, maxHeight = -inf;

int height[maxn];

int prv[maxn];
int nxt[maxn];

int calcRectangle()
{
    stack<int> stprv;

    for (int i = 1; i <= m; ++i)
    {
        while (!stprv.empty() && height[stprv.top()] >= height[i])
        {
            stprv.pop();
        }

        if (!stprv.empty())
        {
            prv[i] = stprv.top();
        }
        else
        {
            prv[i] = 0;
        }

        stprv.push(i);
    }

    stack<int> stnxt;

    for (int i = m; i >= 1; --i)
    {
        while (!stnxt.empty() && height[stnxt.top()] >= height[i])
        {
            stnxt.pop();
        }

        if (!stnxt.empty())
        {
            nxt[i] = stnxt.top();
        }
        else
        {
            nxt[i] = m + 1;
        }

        stnxt.push(i);
    }

    int ans = 0;

    for (int i = 1; i <= m; ++i)
    {
        ans = max(ans, height[i] * (nxt[i] - prv[i] - 1));
    }

    return ans;
}

int area = 0;

bool check(int leastHeight)
{
    for (int i = 1; i <= m; ++i)
    {
        height[i] = 0;
    }

    area = -1;

    for (int i = 1; i <= n; ++i)
    {
        for (int j = 1; j <= m; ++j)
        {
            if (a[i][j] >= leastHeight)
            {
                ++height[j];
            }
            else
            {
                height[j] = 0;
            }
        }

        int res = calcRectangle();
        area = max(area, res);
    }

    return area >= k;
}

void fastIO()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int main()
{
    fastIO();

    cin >> n >> m >> k;

    for (int i = 1; i <= n; ++i)
    {
        for (int j = 1; j <= m; ++j)
        {
            cin >> a[i][j];
            minHeight = min(minHeight, a[i][j]);
            maxHeight = max(maxHeight, a[i][j]);
        }
    }

    int l = minHeight;
    int r = maxHeight;

    while (l <= r)
    {
        int mid = (l + r) / 2;

        if (check(mid) == true)
        {
            l = mid + 1;
        }
        else
        {
            r = mid - 1;
        }
    }

    check(r);

    cout << r << ' ' << area << endl;

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 464 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 3 ms 2652 KB Output is correct
9 Correct 5 ms 2652 KB Output is correct
10 Correct 18 ms 2908 KB Output is correct
11 Correct 36 ms 3164 KB Output is correct
12 Correct 11 ms 2648 KB Output is correct
13 Correct 27 ms 2904 KB Output is correct
14 Correct 36 ms 3160 KB Output is correct
15 Correct 46 ms 3164 KB Output is correct
16 Correct 72 ms 3748 KB Output is correct
17 Correct 29 ms 3164 KB Output is correct
18 Correct 163 ms 5588 KB Output is correct
19 Correct 133 ms 5048 KB Output is correct
20 Correct 413 ms 9304 KB Output is correct
21 Correct 307 ms 10236 KB Output is correct
22 Correct 441 ms 14044 KB Output is correct
23 Correct 461 ms 13924 KB Output is correct
24 Correct 222 ms 6992 KB Output is correct
25 Correct 162 ms 6992 KB Output is correct