답안 #885645

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
885645 2023-12-10T11:18:01 Z alexdd Bomb (IZhO17_bomb) C++17
48 / 100
1000 ms 58204 KB
#include<iostream>
using namespace std;
int n,m;
char mat[2505][2505];
int sump[2505][2505];
int mars[2505][2505];
int pver[2505][2505];
bool verif(int cntx, int cnty)
{
    if(pver[cntx][cnty]!=0)
    {
        if(pver[cntx][cnty]==-1)
            return 0;
        else
            return 1;
    }
    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]++;
            }
            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')
            {
                pver[cntx][cnty]=-1;
                return 0;
            }
        }
    }
    pver[cntx][cnty]=1;
    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;
        poz = max(poz, (mxm-1)/i+1);
        while(poz+1<=miny && verif(i,poz+1))
        {
            poz++;
        }
        if(verif(i,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;
        poz = max(poz, (mxm-1)/i+1);
        while(poz+1<=minx && verif(poz+1,i))
        {
            poz++;
        }
        if(verif(poz,i)) mxm = max(mxm, i*poz);
    }
    cout<<mxm;
}
int calcmax_x(int i, int st, int dr)
{
    int mij,ans=0;
    while(st<=dr)
    {
        mij=(st+dr)/2;
        if(verif(mij,i))
        {
            ans = max(ans, mij);
            st=mij+1;
        }
        else
        {
            dr=mij-1;
        }
    }
    return ans;
}
int solve_bulaneala(int minx, int miny)
{
    int mxm=0,prec=1;
    for(int i=miny;i>max(0,miny-3);i--)
    {
        if(i*minx <= mxm)
            break;
        int st,dr,mij,ans=0;
        st=max(prec, (mxm-1)/i+1);
        dr=minx;
        mxm = max(mxm, i*calcmax_x(i,st,dr));
        prec=ans;
    }
    prec=1;
    for(int i=minx;i>0;i--)
    {
        if(i*miny <= mxm)
            break;
        int st,dr,mij,ans=0;
        st=max(prec, (mxm-1)/i+1);
        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;
    }
    return mxm;
}
int solve_cautare_ternara(int minx, int miny)
{
    int st,dr;
    st=1;
    dr=miny;
    while(dr-st+1>3)
    {
        int mij1 = st + (dr-st+1)/3;
        int mij2 = mij1 + (dr-st+1)/3;
        if(calcmax_x(mij1,1,minx)*mij1 > calcmax_x(mij2,1,minx)*mij2)
        {
            dr=mij2;
        }
        else
        {
            st=mij1;
        }
    }
    int mxm=0;
    for(int i=st;i<=dr;i++)
        mxm = max(mxm, calcmax_x(i,1,minx)*i);
    return 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)
    {
        cout<<max(solve_bulaneala(minx,miny), solve_cautare_ternara(minx,miny));
        return 0;
    }
    else
    {
        cout<<minx*miny;
        return 0;
    }
    return 0;
}

Compilation message

bomb.cpp: In function 'int solve_bulaneala(int, int)':
bomb.cpp:99:19: warning: unused variable 'mij' [-Wunused-variable]
   99 |         int st,dr,mij,ans=0;
      |                   ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 10 ms 42844 KB Output is correct
4 Correct 8 ms 42844 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4440 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4440 KB Output is correct
13 Correct 1 ms 4440 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 6748 KB Output is correct
18 Correct 1 ms 6748 KB Output is correct
19 Correct 2 ms 7000 KB Output is correct
20 Correct 2 ms 7004 KB Output is correct
21 Correct 1 ms 6748 KB Output is correct
22 Correct 1 ms 6748 KB Output is correct
23 Correct 2 ms 7004 KB Output is correct
24 Correct 1 ms 7004 KB Output is correct
25 Correct 2 ms 7000 KB Output is correct
26 Correct 2 ms 7004 KB Output is correct
27 Correct 6 ms 12124 KB Output is correct
28 Correct 7 ms 12120 KB Output is correct
29 Incorrect 29 ms 12636 KB Output isn't correct
30 Correct 45 ms 13472 KB Output is correct
31 Correct 32 ms 12892 KB Output is correct
32 Correct 40 ms 13140 KB Output is correct
33 Correct 111 ms 15852 KB Output is correct
34 Correct 6 ms 12380 KB Output is correct
35 Correct 46 ms 15196 KB Output is correct
36 Correct 24 ms 15364 KB Output is correct
37 Correct 1 ms 4444 KB Output is correct
38 Correct 990 ms 57564 KB Output is correct
39 Correct 1 ms 4440 KB Output is correct
40 Correct 970 ms 24588 KB Output is correct
41 Correct 1 ms 4444 KB Output is correct
42 Correct 2 ms 7004 KB Output is correct
43 Execution timed out 1081 ms 57472 KB Time limit exceeded
44 Correct 81 ms 15956 KB Output is correct
45 Execution timed out 1083 ms 57680 KB Time limit exceeded
46 Correct 722 ms 57308 KB Output is correct
47 Execution timed out 1020 ms 57784 KB Time limit exceeded
48 Execution timed out 1072 ms 57428 KB Time limit exceeded
49 Correct 287 ms 57320 KB Output is correct
50 Execution timed out 1072 ms 57452 KB Time limit exceeded
51 Execution timed out 1014 ms 57788 KB Time limit exceeded
52 Execution timed out 1075 ms 57712 KB Time limit exceeded
53 Execution timed out 1061 ms 57840 KB Time limit exceeded
54 Execution timed out 1035 ms 57836 KB Time limit exceeded
55 Execution timed out 1047 ms 57476 KB Time limit exceeded
56 Correct 749 ms 57460 KB Output is correct
57 Execution timed out 1049 ms 57596 KB Time limit exceeded
58 Execution timed out 1071 ms 57428 KB Time limit exceeded
59 Execution timed out 1056 ms 57940 KB Time limit exceeded
60 Execution timed out 1043 ms 57424 KB Time limit exceeded
61 Correct 601 ms 57508 KB Output is correct
62 Execution timed out 1022 ms 57424 KB Time limit exceeded
63 Execution timed out 1055 ms 57516 KB Time limit exceeded
64 Execution timed out 1008 ms 57424 KB Time limit exceeded
65 Execution timed out 1062 ms 57428 KB Time limit exceeded
66 Correct 384 ms 57936 KB Output is correct
67 Execution timed out 1025 ms 57312 KB Time limit exceeded
68 Execution timed out 1057 ms 57316 KB Time limit exceeded
69 Execution timed out 1071 ms 57428 KB Time limit exceeded
70 Execution timed out 1062 ms 50264 KB Time limit exceeded
71 Execution timed out 1039 ms 57496 KB Time limit exceeded
72 Execution timed out 1002 ms 57316 KB Time limit exceeded
73 Execution timed out 1056 ms 57476 KB Time limit exceeded
74 Execution timed out 1054 ms 57500 KB Time limit exceeded
75 Execution timed out 1041 ms 57680 KB Time limit exceeded
76 Execution timed out 1034 ms 57316 KB Time limit exceeded
77 Execution timed out 1012 ms 57316 KB Time limit exceeded
78 Execution timed out 1041 ms 57424 KB Time limit exceeded
79 Execution timed out 1028 ms 58196 KB Time limit exceeded
80 Execution timed out 1054 ms 58204 KB Time limit exceeded
81 Execution timed out 1066 ms 57672 KB Time limit exceeded
82 Execution timed out 1047 ms 57560 KB Time limit exceeded
83 Execution timed out 1071 ms 57428 KB Time limit exceeded
84 Execution timed out 1038 ms 57696 KB Time limit exceeded
85 Execution timed out 1058 ms 57448 KB Time limit exceeded
86 Execution timed out 1050 ms 57460 KB Time limit exceeded
87 Execution timed out 1056 ms 57484 KB Time limit exceeded
88 Execution timed out 1075 ms 57320 KB Time limit exceeded
89 Execution timed out 1057 ms 57460 KB Time limit exceeded
90 Execution timed out 1029 ms 50464 KB Time limit exceeded
91 Execution timed out 1099 ms 57680 KB Time limit exceeded
92 Execution timed out 1060 ms 57472 KB Time limit exceeded
93 Execution timed out 1020 ms 57760 KB Time limit exceeded
94 Execution timed out 1086 ms 57500 KB Time limit exceeded
95 Execution timed out 1046 ms 57696 KB Time limit exceeded
96 Execution timed out 1085 ms 57364 KB Time limit exceeded
97 Correct 981 ms 57832 KB Output is correct
98 Execution timed out 1069 ms 57496 KB Time limit exceeded
99 Execution timed out 1037 ms 57492 KB Time limit exceeded
100 Execution timed out 1049 ms 57464 KB Time limit exceeded