답안 #895988

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
895988 2023-12-31T11:14:52 Z heeheeheehaaw 호화 벙커 (IZhO13_burrow) C++17
0 / 100
2000 ms 7372 KB
#include <iostream>
#pragma GCC optimize("O3,unroll-loops")

using namespace std;

int a[1005][1005];
int sp[1005][1005];
int n, m, k;

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]++;
            sp[i][j] += sp[i - 1][j] + sp[i][j - 1] - sp[i - 1][j - 1];
        }

    for(int i = 1; i <= n; i++)
    {
        int le = -1;
        for(int j = 1; j <= m; j++)
        {
            if(a[i][j] < minn)
                le = -1;
            else
            {
                if(le == -1) le = j;
                int st = i, dr = n, pozj = i;
                while(st <= dr)
                {
                    int mij = (st + dr) / 2;
                    if(partsum(i, mij, le, j) == calcarie(i, mij, le, j))
                        pozj = mij, st = mij + 1;
                    else
                        dr = mij - 1;
                }

                dr = i, st = 1;
                int pozs = i;
                while(st <= dr)
                {
                    int mij = (st + dr) / 2;
                    if(partsum(mij, i, le, j) == calcarie(mij, i, le, j))
                        pozs = mij, dr = mij - 1;
                    else
                        st = mij + 1;
                }

                int arie = (j - le + 1) * (pozj - pozs + 1);
                maxx = max(maxx, arie);
            }
        }

        int ri = -1;
        for(int j = m; j >= 1; j--)
        {
            if(a[i][j] < minn)
                ri = -1;
            else
            {
                if(ri == -1) ri = j;
                int st = i, dr = n, pozj = i;
                while(st <= dr)
                {
                    int mij = (st + dr) / 2;
                    if(partsum(i, mij, j, ri) == calcarie(i, mij, j, ri))
                        pozj = mij, st = mij + 1;
                    else
                        dr = mij - 1;
                }

                dr = i, st = 1;
                int pozs = i;
                while(st <= dr)
                {
                    int mij = (st + dr) / 2;
                    if(partsum(mij, i, j, ri) == calcarie(i, mij, j, ri))
                        pozs = mij, dr = mij - 1;
                    else
                        st = mij + 1;
                }

                int arie = (ri - j + 1) * (pozj - pozs + 1);
                maxx = max(maxx, arie);
            }
        }
    }

    for(int j = 1; j <= m; j++)
    {
        int sus = -1;
        for(int i = 1; i <= n; i++)
        {
            if(a[i][j] < minn)
                sus = -1;
            else
            {
                if(sus == -1) sus = i;
                int st = j, dr = m, pozdr = j;
                while(st <= dr)
                {
                    int mij = (st + dr) / 2;
                    if(partsum(sus, i, j, mij) == calcarie(sus, i, j, mij))
                        pozdr = mij, st = mij + 1;
                    else
                        dr = mij - 1;
                }

                dr = j, st = 1;
                int pozst = j;
                while(st <= dr)
                {
                    int mij = (st + dr) / 2;
                    if(partsum(sus, i, mij, j) == calcarie(sus, i, mij, j))
                        pozst = mij, dr = mij - 1;
                    else
                        st = mij + 1;
                }

                int arie = (pozdr - pozst + 1) * (i - sus + 1);
                maxx = max(maxx, arie);
            }
        }

        int jos = -1;
        for(int i = n; i >= 1; i--)
        {
            if(a[i][j] < minn)
                jos = -1;
            else
            {
                if(jos == -1) jos = i;
                int st = j, dr = m, pozdr = j;
                while(st <= dr)
                {
                    int mij = (st + dr) / 2;
                    if(partsum(i, jos, j, mij) == calcarie(i, jos, j, mij))
                        pozdr = mij, st = mij + 1;
                    else
                        dr = mij - 1;
                }

                dr = j, st = 1;
                int pozst = j;
                while(st <= dr)
                {
                    int mij = (st + dr) / 2;
                    if(partsum(i, jos, mij, j) == calcarie(i, jos, mij, j))
                        pozst = mij, dr = mij - 1;
                    else
                        st = mij + 1;
                }

                int arie = (pozdr - pozst + 1) * (jos - i + 1);
                maxx = max(maxx, arie);
            }
        }
    }

    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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 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 2592 KB Output is correct
5 Correct 3 ms 2396 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 2 ms 2396 KB Output is correct
8 Correct 12 ms 6800 KB Output is correct
9 Correct 32 ms 6800 KB Output is correct
10 Correct 59 ms 6748 KB Output is correct
11 Correct 261 ms 6744 KB Output is correct
12 Correct 62 ms 6772 KB Output is correct
13 Correct 80 ms 6744 KB Output is correct
14 Correct 245 ms 6776 KB Output is correct
15 Correct 241 ms 6772 KB Output is correct
16 Correct 499 ms 6776 KB Output is correct
17 Correct 100 ms 6744 KB Output is correct
18 Correct 1353 ms 6776 KB Output is correct
19 Correct 861 ms 7144 KB Output is correct
20 Execution timed out 2062 ms 7372 KB Time limit exceeded
21 Halted 0 ms 0 KB -