Submission #474288

# Submission time Handle Problem Language Result Execution time Memory
474288 2021-09-17T18:55:17 Z ogibogi2004 Bomb (IZhO17_bomb) C++14
90 / 100
472 ms 56900 KB
#include<bits/stdc++.h>
using namespace std;
const int MAXN=2502;
char t[MAXN][MAXN];
int n,m,maxw,maxh;
vector<pair<int,int> >segments[MAXN];
vector<pair<int,int> >mws[MAXN];
int up[MAXN][MAXN];
int down[MAXN][MAXN];
int ans[MAXN];
int main()
{
    cin>>n>>m;
    maxh=n;
    maxw=m;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            cin>>t[i][j];
        }
    }
    for(int i=1;i<=n;i++)
    {
        ans[i]=n*m;
        int cnt=0;
        for(int j=1;j<=m;j++)
        {
            ans[j]=n*m;
            if(t[i][j]=='1')cnt++;
            else
            {
                if(cnt>0)maxw=min(maxw,cnt);
                cnt=0;
            }
        }
        if(cnt>0)maxw=min(maxw,cnt);
    }
    //cout<<maxw<<endl;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(t[i][j]=='0')up[i][j]=-1;
            else
            {
                if(up[i-1][j]>0)up[i][j]=up[i-1][j];
                else up[i][j]=i;
            }
        }
    }
    for(int i=n;i>=1;i--)
    {
        for(int j=1;j<=m;j++)
        {
            if(t[i][j]=='0')down[i][j]=-1;
            else
            {
                if(down[i+1][j]>0)down[i][j]=down[i+1][j];
                else down[i][j]=i;
            }
        }
    }
    for(int i=1;i<=n;i++)
    {
        int cnt=0;
        for(int j=1;j<=m;j++)
        {
            if(t[i][j]=='0')
            {
                if(cnt>0)mws[i].push_back({j-cnt,j-1});
                cnt=0;
            }
            else cnt++;
        }
        if(cnt>0)mws[i].push_back({m-cnt+1,m});
    }
    /*for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            cout<<up[i][j]<<" ";
        }
        cout<<endl;
    }
    cout<<endl;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            cout<<down[i][j]<<" ";
        }
        cout<<endl;
    }
    cout<<endl;*/
    for(int i=1;i<=n;i++)
    {
        //cout<<i<<":\n";
        for(int j=0;j<mws[i].size();j++)
        {
            int start=mws[i][j].first;
            int mindown=n+1,maxup=-1;
            for(int len=1;start+len-1<=mws[i][j].second;len++)
            {
                mindown=min(mindown,down[i][start+len-1]);
                maxup=max(maxup,up[i][start+len-1]);
                //cout<<mws[i][j].first<<" "<<len<<" "<<mindown<<" "<<maxup<<endl;
                //cout<<mindown<<" "<<maxup<<endl;
                //cout<<mindown<<" "<<maxup<<endl;
                ans[len]=min(ans[len],len*(mindown-maxup+1));
            }
            start=mws[i][j].second;
            mindown=n+1;maxup=-1;
            for(int len=1;start-len+1>=mws[i][j].first;len++)
            {
                mindown=min(mindown,down[i][start-len+1]);
                maxup=max(maxup,up[i][start-len+1]);
                //cout<<mws[i][j].second<<" "<<len<<" "<<mindown<<" "<<maxup<<endl;
                ans[len]=min(ans[len],len*(mindown-maxup+1));
            }
        }
    }
    if(maxw==0)
    {
        cout<<0<<endl;
        return 0;
    }
    int ans1=0;
    for(int i=1;i<=maxw;i++)
    {
        //cout<<ans[i]<<" ";
        ans1=max(ans1,ans[i]);
    }
    //cout<<endl;
    cout<<ans1<<endl;
return 0;
}

Compilation message

bomb.cpp: In function 'int main()':
bomb.cpp:99:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   99 |         for(int j=0;j<mws[i].size();j++)
      |                     ~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 588 KB Output is correct
3 Correct 12 ms 26708 KB Output is correct
4 Correct 12 ms 26700 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Incorrect 1 ms 460 KB Output isn't correct
8 Correct 1 ms 588 KB Output is correct
9 Correct 1 ms 588 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 588 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 588 KB Output is correct
15 Correct 1 ms 588 KB Output is correct
16 Correct 1 ms 588 KB Output is correct
17 Correct 1 ms 1100 KB Output is correct
18 Correct 1 ms 1100 KB Output is correct
19 Correct 1 ms 1356 KB Output is correct
20 Correct 2 ms 1356 KB Output is correct
21 Correct 1 ms 972 KB Output is correct
22 Correct 1 ms 1228 KB Output is correct
23 Correct 2 ms 1484 KB Output is correct
24 Correct 1 ms 1228 KB Output is correct
25 Correct 2 ms 1556 KB Output is correct
26 Incorrect 2 ms 1484 KB Output isn't correct
27 Incorrect 9 ms 4044 KB Output isn't correct
28 Correct 9 ms 4284 KB Output is correct
29 Correct 11 ms 5496 KB Output is correct
30 Correct 15 ms 6336 KB Output is correct
31 Correct 12 ms 5060 KB Output is correct
32 Correct 13 ms 5836 KB Output is correct
33 Correct 16 ms 6728 KB Output is correct
34 Correct 8 ms 4736 KB Output is correct
35 Correct 17 ms 6732 KB Output is correct
36 Incorrect 17 ms 6652 KB Output isn't correct
37 Correct 1 ms 588 KB Output is correct
38 Correct 448 ms 55552 KB Output is correct
39 Correct 1 ms 588 KB Output is correct
40 Correct 60 ms 15532 KB Output is correct
41 Correct 1 ms 588 KB Output is correct
42 Correct 2 ms 1484 KB Output is correct
43 Correct 438 ms 55572 KB Output is correct
44 Correct 16 ms 6732 KB Output is correct
45 Correct 434 ms 55528 KB Output is correct
46 Correct 445 ms 56764 KB Output is correct
47 Correct 438 ms 55500 KB Output is correct
48 Correct 434 ms 55532 KB Output is correct
49 Incorrect 442 ms 55664 KB Output isn't correct
50 Correct 437 ms 55580 KB Output is correct
51 Correct 472 ms 55616 KB Output is correct
52 Correct 431 ms 55620 KB Output is correct
53 Correct 439 ms 55492 KB Output is correct
54 Correct 421 ms 55632 KB Output is correct
55 Correct 424 ms 55504 KB Output is correct
56 Correct 451 ms 56900 KB Output is correct
57 Correct 426 ms 55468 KB Output is correct
58 Correct 424 ms 55492 KB Output is correct
59 Correct 422 ms 55528 KB Output is correct
60 Incorrect 431 ms 55624 KB Output isn't correct
61 Incorrect 448 ms 55568 KB Output isn't correct
62 Incorrect 446 ms 55576 KB Output isn't correct
63 Incorrect 445 ms 55536 KB Output isn't correct
64 Incorrect 421 ms 55712 KB Output isn't correct
65 Correct 430 ms 55564 KB Output is correct
66 Correct 433 ms 55492 KB Output is correct
67 Correct 440 ms 55548 KB Output is correct
68 Correct 459 ms 55492 KB Output is correct
69 Correct 443 ms 55520 KB Output is correct
70 Correct 277 ms 44416 KB Output is correct
71 Correct 417 ms 55552 KB Output is correct
72 Correct 426 ms 55556 KB Output is correct
73 Correct 426 ms 55552 KB Output is correct
74 Correct 425 ms 55668 KB Output is correct
75 Correct 429 ms 55492 KB Output is correct
76 Correct 430 ms 55464 KB Output is correct
77 Correct 418 ms 55452 KB Output is correct
78 Correct 426 ms 55520 KB Output is correct
79 Correct 421 ms 55492 KB Output is correct
80 Correct 413 ms 55492 KB Output is correct
81 Correct 422 ms 55492 KB Output is correct
82 Correct 421 ms 55492 KB Output is correct
83 Correct 422 ms 55620 KB Output is correct
84 Correct 405 ms 55456 KB Output is correct
85 Correct 426 ms 55548 KB Output is correct
86 Correct 446 ms 55560 KB Output is correct
87 Correct 422 ms 55624 KB Output is correct
88 Correct 422 ms 55568 KB Output is correct
89 Correct 426 ms 55524 KB Output is correct
90 Correct 269 ms 44508 KB Output is correct
91 Correct 427 ms 55472 KB Output is correct
92 Correct 427 ms 55512 KB Output is correct
93 Correct 437 ms 55464 KB Output is correct
94 Correct 427 ms 55620 KB Output is correct
95 Correct 417 ms 55548 KB Output is correct
96 Correct 421 ms 55620 KB Output is correct
97 Correct 436 ms 55492 KB Output is correct
98 Correct 433 ms 55596 KB Output is correct
99 Correct 427 ms 55460 KB Output is correct
100 Correct 439 ms 55572 KB Output is correct