# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
474286 |
2021-09-17T18:52:38 Z |
ogibogi2004 |
Bomb (IZhO17_bomb) |
C++14 |
|
491 ms |
56772 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));
}
}
}
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 |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
588 KB |
Output is correct |
3 |
Correct |
13 ms |
26640 KB |
Output is correct |
4 |
Correct |
13 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 |
588 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 |
1 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 |
8 ms |
4116 KB |
Output isn't correct |
28 |
Correct |
11 ms |
4300 KB |
Output is correct |
29 |
Correct |
11 ms |
5508 KB |
Output is correct |
30 |
Correct |
15 ms |
6348 KB |
Output is correct |
31 |
Correct |
13 ms |
5068 KB |
Output is correct |
32 |
Correct |
13 ms |
5836 KB |
Output is correct |
33 |
Correct |
17 ms |
6696 KB |
Output is correct |
34 |
Correct |
8 ms |
4684 KB |
Output is correct |
35 |
Correct |
18 ms |
6728 KB |
Output is correct |
36 |
Incorrect |
17 ms |
6732 KB |
Output isn't correct |
37 |
Correct |
1 ms |
588 KB |
Output is correct |
38 |
Correct |
458 ms |
55584 KB |
Output is correct |
39 |
Correct |
1 ms |
588 KB |
Output is correct |
40 |
Correct |
60 ms |
15724 KB |
Output is correct |
41 |
Correct |
1 ms |
588 KB |
Output is correct |
42 |
Correct |
2 ms |
1484 KB |
Output is correct |
43 |
Correct |
434 ms |
55492 KB |
Output is correct |
44 |
Correct |
17 ms |
6724 KB |
Output is correct |
45 |
Correct |
477 ms |
55600 KB |
Output is correct |
46 |
Correct |
441 ms |
56772 KB |
Output is correct |
47 |
Correct |
432 ms |
55644 KB |
Output is correct |
48 |
Correct |
432 ms |
55488 KB |
Output is correct |
49 |
Incorrect |
451 ms |
55560 KB |
Output isn't correct |
50 |
Correct |
431 ms |
55528 KB |
Output is correct |
51 |
Correct |
440 ms |
55496 KB |
Output is correct |
52 |
Correct |
470 ms |
55620 KB |
Output is correct |
53 |
Correct |
430 ms |
55556 KB |
Output is correct |
54 |
Correct |
425 ms |
55552 KB |
Output is correct |
55 |
Correct |
448 ms |
55544 KB |
Output is correct |
56 |
Correct |
491 ms |
56716 KB |
Output is correct |
57 |
Correct |
430 ms |
55516 KB |
Output is correct |
58 |
Correct |
421 ms |
55536 KB |
Output is correct |
59 |
Correct |
419 ms |
55556 KB |
Output is correct |
60 |
Incorrect |
455 ms |
55540 KB |
Output isn't correct |
61 |
Incorrect |
442 ms |
55652 KB |
Output isn't correct |
62 |
Incorrect |
448 ms |
55500 KB |
Output isn't correct |
63 |
Incorrect |
445 ms |
55576 KB |
Output isn't correct |
64 |
Incorrect |
420 ms |
55692 KB |
Output isn't correct |
65 |
Correct |
437 ms |
55552 KB |
Output is correct |
66 |
Correct |
427 ms |
55532 KB |
Output is correct |
67 |
Correct |
442 ms |
55616 KB |
Output is correct |
68 |
Correct |
435 ms |
55492 KB |
Output is correct |
69 |
Correct |
442 ms |
55440 KB |
Output is correct |
70 |
Correct |
266 ms |
44484 KB |
Output is correct |
71 |
Correct |
457 ms |
55520 KB |
Output is correct |
72 |
Correct |
438 ms |
55432 KB |
Output is correct |
73 |
Correct |
456 ms |
55504 KB |
Output is correct |
74 |
Correct |
427 ms |
55528 KB |
Output is correct |
75 |
Correct |
437 ms |
55468 KB |
Output is correct |
76 |
Correct |
434 ms |
55528 KB |
Output is correct |
77 |
Correct |
441 ms |
55492 KB |
Output is correct |
78 |
Correct |
428 ms |
55540 KB |
Output is correct |
79 |
Correct |
415 ms |
55536 KB |
Output is correct |
80 |
Correct |
412 ms |
55516 KB |
Output is correct |
81 |
Correct |
408 ms |
55504 KB |
Output is correct |
82 |
Correct |
428 ms |
55544 KB |
Output is correct |
83 |
Correct |
429 ms |
55504 KB |
Output is correct |
84 |
Correct |
419 ms |
55388 KB |
Output is correct |
85 |
Correct |
421 ms |
55568 KB |
Output is correct |
86 |
Correct |
451 ms |
55572 KB |
Output is correct |
87 |
Correct |
418 ms |
55664 KB |
Output is correct |
88 |
Correct |
433 ms |
55588 KB |
Output is correct |
89 |
Correct |
427 ms |
55576 KB |
Output is correct |
90 |
Correct |
273 ms |
44484 KB |
Output is correct |
91 |
Correct |
422 ms |
55548 KB |
Output is correct |
92 |
Correct |
427 ms |
55540 KB |
Output is correct |
93 |
Correct |
483 ms |
55492 KB |
Output is correct |
94 |
Correct |
430 ms |
55524 KB |
Output is correct |
95 |
Correct |
423 ms |
55468 KB |
Output is correct |
96 |
Correct |
434 ms |
55492 KB |
Output is correct |
97 |
Correct |
444 ms |
55456 KB |
Output is correct |
98 |
Correct |
477 ms |
55488 KB |
Output is correct |
99 |
Correct |
430 ms |
55528 KB |
Output is correct |
100 |
Correct |
453 ms |
55472 KB |
Output is correct |