답안 #474291

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
474291 2021-09-17T18:57:43 Z ogibogi2004 Bomb (IZhO17_bomb) C++14
90 / 100
468 ms 56972 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<<-1<<endl;
        return 0;
    }
    int ans1=0;
    for(int i=1;i<=maxw;i++)
    {
        if(i!=1)ans[i]=min(ans[i],i*(ans[i-1]/(i-1)));
        //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++)
      |                     ~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 588 KB Output is correct
3 Correct 14 ms 26684 KB Output is correct
4 Correct 11 ms 26620 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Incorrect 0 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 1428 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 1484 KB Output is correct
26 Incorrect 2 ms 1484 KB Output isn't correct
27 Incorrect 7 ms 4044 KB Output isn't correct
28 Correct 9 ms 4300 KB Output is correct
29 Correct 11 ms 5436 KB Output is correct
30 Correct 15 ms 6348 KB Output is correct
31 Correct 12 ms 5068 KB Output is correct
32 Correct 13 ms 5896 KB Output is correct
33 Correct 16 ms 6732 KB Output is correct
34 Correct 7 ms 4700 KB Output is correct
35 Correct 16 ms 6744 KB Output is correct
36 Incorrect 19 ms 6748 KB Output isn't correct
37 Correct 1 ms 588 KB Output is correct
38 Correct 441 ms 55620 KB Output is correct
39 Correct 1 ms 588 KB Output is correct
40 Correct 69 ms 15572 KB Output is correct
41 Correct 1 ms 588 KB Output is correct
42 Correct 2 ms 1484 KB Output is correct
43 Correct 442 ms 55572 KB Output is correct
44 Correct 16 ms 6732 KB Output is correct
45 Correct 436 ms 55512 KB Output is correct
46 Correct 448 ms 56772 KB Output is correct
47 Correct 436 ms 55604 KB Output is correct
48 Correct 426 ms 55564 KB Output is correct
49 Incorrect 442 ms 55492 KB Output isn't correct
50 Correct 426 ms 55492 KB Output is correct
51 Correct 430 ms 55568 KB Output is correct
52 Correct 432 ms 55464 KB Output is correct
53 Correct 425 ms 55548 KB Output is correct
54 Correct 418 ms 55536 KB Output is correct
55 Correct 423 ms 55552 KB Output is correct
56 Correct 461 ms 56972 KB Output is correct
57 Correct 424 ms 55492 KB Output is correct
58 Correct 428 ms 55580 KB Output is correct
59 Correct 429 ms 55560 KB Output is correct
60 Incorrect 431 ms 55720 KB Output isn't correct
61 Incorrect 440 ms 55600 KB Output isn't correct
62 Incorrect 449 ms 55524 KB Output isn't correct
63 Incorrect 443 ms 55552 KB Output isn't correct
64 Incorrect 426 ms 55496 KB Output isn't correct
65 Correct 437 ms 55568 KB Output is correct
66 Correct 434 ms 55524 KB Output is correct
67 Correct 438 ms 55572 KB Output is correct
68 Correct 431 ms 55668 KB Output is correct
69 Correct 422 ms 55480 KB Output is correct
70 Correct 274 ms 44524 KB Output is correct
71 Correct 412 ms 55512 KB Output is correct
72 Correct 415 ms 55568 KB Output is correct
73 Correct 427 ms 55492 KB Output is correct
74 Correct 414 ms 55512 KB Output is correct
75 Correct 429 ms 55548 KB Output is correct
76 Correct 423 ms 55492 KB Output is correct
77 Correct 428 ms 55464 KB Output is correct
78 Correct 466 ms 55492 KB Output is correct
79 Correct 415 ms 55492 KB Output is correct
80 Correct 419 ms 55520 KB Output is correct
81 Correct 415 ms 55484 KB Output is correct
82 Correct 433 ms 55532 KB Output is correct
83 Correct 423 ms 55488 KB Output is correct
84 Correct 425 ms 55460 KB Output is correct
85 Correct 442 ms 55552 KB Output is correct
86 Correct 468 ms 55612 KB Output is correct
87 Correct 420 ms 55624 KB Output is correct
88 Correct 428 ms 55576 KB Output is correct
89 Correct 425 ms 55476 KB Output is correct
90 Correct 286 ms 44620 KB Output is correct
91 Correct 423 ms 55576 KB Output is correct
92 Correct 431 ms 55536 KB Output is correct
93 Correct 443 ms 55484 KB Output is correct
94 Correct 425 ms 55576 KB Output is correct
95 Correct 422 ms 55492 KB Output is correct
96 Correct 426 ms 55524 KB Output is correct
97 Correct 446 ms 55480 KB Output is correct
98 Correct 418 ms 55548 KB Output is correct
99 Correct 433 ms 55492 KB Output is correct
100 Correct 449 ms 55504 KB Output is correct