답안 #885637

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
885637 2023-12-10T10:40:19 Z alexdd Bomb (IZhO17_bomb) C++17
67 / 100
1000 ms 58064 KB
#include<iostream>
using namespace std;
const int NRNM = 10;
int n,m,cntnm;
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;
    }
    cntnm++;
    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;
}
void solve_bulaneala(int minx, int miny)
{
    int mxm=0,prec=1;
    cntnm=0;
    for(int i=miny;i>0;i--)
    {
        if(i*minx <= mxm)
            break;
        int st,dr,mij,ans=0;
        st=max(prec, (mxm-1)/i+1);
        dr=minx;
        if(cntnm>=NRNM)
            break;
        if(!verif(st,i))
            continue;
        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;
    cntnm=0;
    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;
        if(cntnm>=NRNM)
            break;
        if(!verif(i,st))
            continue;
        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 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 9 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 4556 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 4444 KB Output is correct
13 Correct 1 ms 4444 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 7004 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 2 ms 7004 KB Output is correct
25 Correct 2 ms 7004 KB Output is correct
26 Correct 2 ms 7004 KB Output is correct
27 Correct 5 ms 12124 KB Output is correct
28 Correct 7 ms 12124 KB Output is correct
29 Incorrect 29 ms 12800 KB Output isn't correct
30 Correct 44 ms 13404 KB Output is correct
31 Correct 31 ms 12792 KB Output is correct
32 Correct 40 ms 13148 KB Output is correct
33 Correct 110 ms 15796 KB Output is correct
34 Correct 6 ms 12376 KB Output is correct
35 Correct 46 ms 15308 KB Output is correct
36 Correct 24 ms 15196 KB Output is correct
37 Correct 1 ms 4444 KB Output is correct
38 Correct 246 ms 57328 KB Output is correct
39 Correct 1 ms 4444 KB Output is correct
40 Correct 48 ms 23740 KB Output is correct
41 Correct 1 ms 4444 KB Output is correct
42 Correct 2 ms 7004 KB Output is correct
43 Correct 380 ms 57424 KB Output is correct
44 Correct 81 ms 15960 KB Output is correct
45 Incorrect 339 ms 57292 KB Output isn't correct
46 Correct 718 ms 57680 KB Output is correct
47 Incorrect 346 ms 57428 KB Output isn't correct
48 Correct 453 ms 57584 KB Output is correct
49 Correct 282 ms 57312 KB Output is correct
50 Correct 446 ms 57572 KB Output is correct
51 Correct 462 ms 57424 KB Output is correct
52 Correct 438 ms 57568 KB Output is correct
53 Correct 425 ms 57472 KB Output is correct
54 Correct 491 ms 57328 KB Output is correct
55 Correct 480 ms 57688 KB Output is correct
56 Correct 286 ms 57428 KB Output is correct
57 Correct 534 ms 57940 KB Output is correct
58 Correct 569 ms 57568 KB Output is correct
59 Correct 547 ms 57424 KB Output is correct
60 Correct 353 ms 57452 KB Output is correct
61 Correct 598 ms 57680 KB Output is correct
62 Correct 396 ms 57428 KB Output is correct
63 Correct 329 ms 57320 KB Output is correct
64 Correct 375 ms 57424 KB Output is correct
65 Correct 424 ms 57680 KB Output is correct
66 Correct 380 ms 57464 KB Output is correct
67 Correct 425 ms 57720 KB Output is correct
68 Correct 444 ms 57428 KB Output is correct
69 Correct 548 ms 57424 KB Output is correct
70 Incorrect 205 ms 50256 KB Output isn't correct
71 Incorrect 369 ms 57556 KB Output isn't correct
72 Incorrect 346 ms 57432 KB Output isn't correct
73 Incorrect 326 ms 57684 KB Output isn't correct
74 Incorrect 365 ms 57508 KB Output isn't correct
75 Incorrect 356 ms 57428 KB Output isn't correct
76 Incorrect 369 ms 57428 KB Output isn't correct
77 Incorrect 376 ms 57488 KB Output isn't correct
78 Incorrect 376 ms 57344 KB Output isn't correct
79 Execution timed out 1055 ms 58064 KB Time limit exceeded
80 Execution timed out 1028 ms 57880 KB Time limit exceeded
81 Incorrect 299 ms 57424 KB Output isn't correct
82 Incorrect 377 ms 57488 KB Output isn't correct
83 Incorrect 395 ms 57600 KB Output isn't correct
84 Execution timed out 1035 ms 57680 KB Time limit exceeded
85 Incorrect 354 ms 57496 KB Output isn't correct
86 Incorrect 280 ms 57424 KB Output isn't correct
87 Correct 322 ms 57428 KB Output is correct
88 Incorrect 368 ms 57308 KB Output isn't correct
89 Incorrect 301 ms 57428 KB Output isn't correct
90 Incorrect 235 ms 50428 KB Output isn't correct
91 Incorrect 334 ms 57428 KB Output isn't correct
92 Incorrect 346 ms 57576 KB Output isn't correct
93 Incorrect 304 ms 57432 KB Output isn't correct
94 Incorrect 310 ms 57700 KB Output isn't correct
95 Incorrect 389 ms 57424 KB Output isn't correct
96 Incorrect 365 ms 57688 KB Output isn't correct
97 Incorrect 280 ms 57316 KB Output isn't correct
98 Incorrect 394 ms 57828 KB Output isn't correct
99 Incorrect 321 ms 57428 KB Output isn't correct
100 Incorrect 307 ms 57424 KB Output isn't correct