답안 #885340

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
885340 2023-12-09T13:22:47 Z alexdd Bomb (IZhO17_bomb) C++17
68 / 100
1000 ms 55980 KB
#include<iostream>
using namespace std;
int n,m;
char mat[2505][2505];
int sump[2505][2505];
int mars[2505][2505];
bool verif(int cntx, int cnty)
{
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            mars[i][j]=0;
    for(int i=1;i+cntx-1<=n;i++)
    {
        for(int j=1;j+cnty-1<=m;j++)
        {
            if(sump[i+cntx-1][j+cnty-1] - sump[i+cntx-1][j-1] - sump[i-1][j+cnty-1] + sump[i-1][j-1] == cntx*cnty)///toate is 1
            {
                mars[i][j]++;
                mars[i][j+cnty]--;
                mars[i+cntx][j]--;
                mars[i+cntx][j+cnty]++;
            }
        }
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            mars[i][j] += mars[i-1][j] + mars[i][j-1] - mars[i-1][j-1];
            if(mars[i][j]==0 && mat[i][j]=='1')
                return 0;
        }
    }
    return 1;
}
void solve_n3_y(int minx, int miny)
{
    int poz=0, mxm=0;
    for(int i=minx;i>0;i--)
    {
        if(i*miny <= mxm)
            break;
        while(poz+1<=miny && verif(i,poz+1))
        {
            poz++;
        }
        mxm = max(mxm, i*poz);
    }
    cout<<mxm;
}
void solve_n3_x(int minx, int miny)
{
    int poz=0, mxm=0;
    for(int i=miny;i>0;i--)
    {
        if(i*minx <= mxm)
            break;
        while(poz+1<=minx && verif(poz+1,i))
        {
            poz++;
        }
        mxm = max(mxm, i*poz);
    }
    cout<<mxm;
}
void solve_bulaneala(int minx, int miny)
{
    int mxm=0,prec=1;
    for(int i=miny;i>max(0,miny-2);i--)
    {
        if(i*minx <= mxm)
            break;
        int st,dr,mij,ans=0;
        st=prec;
        dr=minx;
        while(st<=dr)
        {
            mij=(st+dr)/2;
            if(verif(mij,i))
            {
                ans = max(ans, mij);
                st=mij+1;
            }
            else
            {
                dr=mij-1;
            }
        }
        mxm = max(mxm, i*ans);
        prec=ans;
    }
    prec=1;
    for(int i=minx;i>max(0,minx-3);i--)
    {
        if(i*miny <= mxm)
            break;
        int st,dr,mij,ans=0;
        st=prec;
        dr=miny;
        while(st<=dr)
        {
            mij=(st+dr)/2;
            if(verif(i,mij))
            {
                ans = max(ans, mij);
                st=mij+1;
            }
            else
            {
                dr=mij-1;
            }
        }
        mxm = max(mxm, i*ans);
        prec=ans;
    }
    cout<<mxm;
}
signed main()
{
    cin>>n>>m;
    int minx=n,miny=m;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            cin>>mat[i][j];
            sump[i][j] = sump[i-1][j] + sump[i][j-1] - sump[i-1][j-1];
            if(mat[i][j]=='1')
                sump[i][j]++;
        }
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(mat[i][j]=='1' && (j==m || mat[i][j+1]=='0'))
            {
                int cnt=0;
                for(int u=j;u>0;u--)
                {
                    if(mat[i][u]=='0')
                        break;
                    cnt++;
                }
                miny = min(miny, cnt);
            }
        }
    }
    for(int i=1;i<=m;i++)
    {
        for(int j=1;j<=n;j++)
        {
            if(mat[j][i]=='1' && (j==n || mat[j+1][i]=='0'))
            {
                int cnt=0;
                for(int u=j;u>0;u--)
                {
                    if(mat[u][i]=='0')
                        break;
                    cnt++;
                }
                minx = min(minx, cnt);
            }
        }
    }
    if(1LL*miny * n * m <= 170000000)
    {
        solve_n3_y(minx,miny);
        return 0;
    }
    else if(1LL*minx*n*m <= 170000000)
    {
        solve_n3_x(minx,miny);
        return 0;
    }
    else if(1)
    {
        solve_bulaneala(minx,miny);
        return 0;
    }
    else
    {
        cout<<minx*miny;
        return 0;
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 8 ms 40796 KB Output is correct
4 Correct 8 ms 40796 KB Output is correct
5 Correct 1 ms 2648 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 4700 KB Output is correct
9 Correct 1 ms 4700 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 4700 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 4700 KB Output is correct
17 Correct 2 ms 4700 KB Output is correct
18 Correct 1 ms 4700 KB Output is correct
19 Correct 2 ms 4956 KB Output is correct
20 Correct 2 ms 4956 KB Output is correct
21 Correct 2 ms 4696 KB Output is correct
22 Correct 1 ms 4952 KB Output is correct
23 Correct 3 ms 4952 KB Output is correct
24 Correct 1 ms 4956 KB Output is correct
25 Correct 2 ms 4952 KB Output is correct
26 Correct 2 ms 4956 KB Output is correct
27 Correct 6 ms 11804 KB Output is correct
28 Correct 9 ms 11868 KB Output is correct
29 Correct 49 ms 12020 KB Output is correct
30 Correct 51 ms 12124 KB Output is correct
31 Correct 46 ms 12124 KB Output is correct
32 Correct 43 ms 11868 KB Output is correct
33 Correct 147 ms 14232 KB Output is correct
34 Correct 8 ms 10332 KB Output is correct
35 Correct 81 ms 14228 KB Output is correct
36 Correct 39 ms 14228 KB Output is correct
37 Correct 1 ms 4700 KB Output is correct
38 Correct 454 ms 55616 KB Output is correct
39 Correct 1 ms 4700 KB Output is correct
40 Correct 92 ms 21952 KB Output is correct
41 Correct 1 ms 4700 KB Output is correct
42 Correct 3 ms 4956 KB Output is correct
43 Correct 454 ms 55380 KB Output is correct
44 Correct 185 ms 14172 KB Output is correct
45 Incorrect 811 ms 55632 KB Output isn't correct
46 Correct 929 ms 55620 KB Output is correct
47 Incorrect 778 ms 55724 KB Output isn't correct
48 Correct 717 ms 55636 KB Output is correct
49 Correct 329 ms 55620 KB Output is correct
50 Correct 748 ms 55620 KB Output is correct
51 Correct 761 ms 55620 KB Output is correct
52 Correct 745 ms 55724 KB Output is correct
53 Correct 737 ms 55620 KB Output is correct
54 Correct 843 ms 55608 KB Output is correct
55 Correct 779 ms 55612 KB Output is correct
56 Correct 470 ms 55616 KB Output is correct
57 Correct 825 ms 55608 KB Output is correct
58 Correct 940 ms 55612 KB Output is correct
59 Correct 878 ms 55648 KB Output is correct
60 Correct 367 ms 55620 KB Output is correct
61 Correct 736 ms 55624 KB Output is correct
62 Correct 496 ms 55380 KB Output is correct
63 Correct 479 ms 55596 KB Output is correct
64 Correct 418 ms 55616 KB Output is correct
65 Correct 725 ms 55616 KB Output is correct
66 Correct 548 ms 55980 KB Output is correct
67 Correct 718 ms 55636 KB Output is correct
68 Correct 764 ms 55616 KB Output is correct
69 Correct 817 ms 55608 KB Output is correct
70 Incorrect 450 ms 48464 KB Output isn't correct
71 Incorrect 821 ms 55384 KB Output isn't correct
72 Incorrect 827 ms 55608 KB Output isn't correct
73 Incorrect 761 ms 55612 KB Output isn't correct
74 Incorrect 865 ms 55612 KB Output isn't correct
75 Incorrect 826 ms 55728 KB Output isn't correct
76 Incorrect 926 ms 55612 KB Output isn't correct
77 Incorrect 883 ms 55472 KB Output isn't correct
78 Incorrect 926 ms 55616 KB Output isn't correct
79 Execution timed out 1056 ms 55380 KB Time limit exceeded
80 Execution timed out 1051 ms 55632 KB Time limit exceeded
81 Incorrect 674 ms 55376 KB Output isn't correct
82 Incorrect 899 ms 55456 KB Output isn't correct
83 Incorrect 914 ms 55616 KB Output isn't correct
84 Execution timed out 1030 ms 55484 KB Time limit exceeded
85 Incorrect 786 ms 55632 KB Output isn't correct
86 Incorrect 597 ms 55620 KB Output isn't correct
87 Correct 777 ms 55644 KB Output is correct
88 Incorrect 804 ms 55844 KB Output isn't correct
89 Incorrect 707 ms 55636 KB Output isn't correct
90 Incorrect 550 ms 48720 KB Output isn't correct
91 Incorrect 792 ms 55636 KB Output isn't correct
92 Incorrect 756 ms 55448 KB Output isn't correct
93 Incorrect 615 ms 55616 KB Output isn't correct
94 Incorrect 718 ms 55888 KB Output isn't correct
95 Incorrect 901 ms 55612 KB Output isn't correct
96 Incorrect 826 ms 55616 KB Output isn't correct
97 Incorrect 600 ms 55620 KB Output isn't correct
98 Incorrect 910 ms 55392 KB Output isn't correct
99 Incorrect 725 ms 55624 KB Output isn't correct
100 Incorrect 615 ms 55468 KB Output isn't correct