답안 #897006

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
897006 2024-01-02T12:16:05 Z borisAngelov 호화 벙커 (IZhO13_burrow) C++17
0 / 100
0 ms 348 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;
    }

    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();

        if (res >= k)
        {
            area = res;
            return true;
        }
    }

    return false;
}

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 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -