Submission #895991

# Submission time Handle Problem Language Result Execution time Memory
895991 2023-12-31T11:33:16 Z heeheeheehaaw Luxury burrow (IZhO13_burrow) C++17
100 / 100
486 ms 18256 KB
#include <bits/stdc++.h>

using namespace std;

int a[1005][1005];
int sp[1005][1005];
int n, m, k;
int hei[1005];
int st[1005], dr[1005];

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

int calcarie(int x1, int x2, int y1, int y2)
{
    return (x2 - x1 + 1) * (y2 - y1 + 1);
}

int solve(int minn)
{
    int maxx = 0;
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++)
        {
            sp[i][j] = 0;
            if(a[i][j] >= minn)
                sp[i][j] = 1;
            hei[j] = 0;
        }

    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= m; j++)
        {
            if(sp[i][j] == 1) hei[j]++;
            else hei[j] = 0;
        }

        stack<int> s;
        for(int j = 1; j <= m; j++)
        {
            while(!s.empty() && hei[s.top()] >= hei[j])
                s.pop();
            if(s.empty()) st[j] = 0;
            else st[j] = s.top();
            s.push(j);
        }

        s = stack<int>{};
        for(int j = m; j >= 1; j--)
        {
            while(!s.empty() && hei[s.top()] >= hei[j])
                s.pop();
            if(s.empty()) dr[j] = m + 1;
            else dr[j] = s.top();
            s.push(j);
        }

        for(int j = 1; j <= m; j++)
            maxx = max(maxx, hei[j] * (dr[j] - st[j] - 1));
    }

    return maxx;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin>>n>>m>>k;
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++)
            cin>>a[i][j];
    int st = 1, dr = 1e9, rez = 0, poz = 0;
    while(st <= dr)
    {
        int mij = (st + dr) / 2;
        int maxx = solve(mij);

        if(maxx >= k)
            poz = mij, rez = maxx, st = mij + 1;
        else
            dr = mij - 1;
    }

    cout<<poz<<" "<<rez<<'\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2480 KB Output is correct
7 Correct 1 ms 2508 KB Output is correct
8 Correct 5 ms 6828 KB Output is correct
9 Correct 7 ms 6748 KB Output is correct
10 Correct 23 ms 7004 KB Output is correct
11 Correct 38 ms 7260 KB Output is correct
12 Correct 20 ms 6748 KB Output is correct
13 Correct 30 ms 7004 KB Output is correct
14 Correct 66 ms 7288 KB Output is correct
15 Correct 73 ms 7300 KB Output is correct
16 Correct 72 ms 7516 KB Output is correct
17 Correct 72 ms 7284 KB Output is correct
18 Correct 203 ms 8272 KB Output is correct
19 Correct 252 ms 8272 KB Output is correct
20 Correct 417 ms 10584 KB Output is correct
21 Correct 405 ms 14004 KB Output is correct
22 Correct 462 ms 18256 KB Output is correct
23 Correct 486 ms 17748 KB Output is correct
24 Correct 365 ms 11088 KB Output is correct
25 Correct 335 ms 11188 KB Output is correct