Submission #366825

# Submission time Handle Problem Language Result Execution time Memory
366825 2021-02-15T10:37:51 Z nicolaalexandra Bomb (IZhO17_bomb) C++14
100 / 100
680 ms 125420 KB
#include <bits/stdc++.h>
#define DIM 2502
using namespace std;

int n,m,i,j;
char s[DIM];
int dp_up[DIM][DIM],dp_down[DIM][DIM],dp_left[DIM][DIM],dp_right[DIM][DIM];
int a[DIM][DIM],dp[DIM];

int main (){

    //ifstream cin ("bomb.in");
    //ofstream cout ("bomb.out");

    cin>>n>>m;
    for (i=1;i<=n;i++){
        cin>>s+1;
        for (j=1;j<=m;j++)
            a[i][j] = s[j] - '0';
    }

    for (i=1;i<=n;i++)
        for (j=1;j<=m;j++){
            if (a[i][j]){
                dp_up[i][j] = 1 + dp_up[i-1][j];
                dp_left[i][j] = 1 + dp_left[i][j-1];
            }}

    for (i=n;i;i--)
        for (j=m;j;j--){
            if (a[i][j]){
                dp_down[i][j] = 1 + dp_down[i+1][j];
                dp_right[i][j] = 1 + dp_right[i][j+1];
            }}

    /// pot sa am maxim dimensiunile h,w
    /// dp[i] - latimea maxima a unui dreptunghi cu inaltimea i

    for (i=1;i<=n;i++)
        dp[i] = m+1;

    int w = m, h = n;
    for (i=1;i<=n;i++)
        for (j=1;j<=m;j++){
            if (!a[i][j])
                continue;
            w = min (w,dp_right[i][j] + dp_left[i][j] - 1);
            h = min (h,dp_up[i][j] + dp_down[i][j] - 1);

            dp[1] = min (dp[1],dp_left[i][j] + dp_right[i][j] - 1);
        }

    for (j=1;j<=m;j++){
        int st = 0, dr = m+1, cnt = 0;
        for (i=1;i<=n;i++){
            if (a[i][j]){
                st = max (st,j - dp_left[i][j] + 1);
                dr = min (dr,j + dp_right[i][j] - 1);
                cnt++;
                dp[cnt] = min (dp[cnt],dr-st+1);
            } else {
                cnt = 0;
                st = 0, dr = m+1;
            }}}

    /// trb sa fac acelasi lucru si invers

    for (j=1;j<=m;j++){
        int st = 0, dr = m+1, cnt = 0;
        for (i=n;i;i--){
            if (a[i][j]){
                st = max (st,j - dp_left[i][j] + 1);
                dr = min (dr,j + dp_right[i][j] - 1);
                cnt++;
                dp[cnt] = min (dp[cnt],dr-st+1);
            } else {
                cnt = 0;
                st = 0, dr = m+1;
            }}}

    int sol = 0;
    for (i=1;i<=h;i++){
        if (i > 1)
            dp[i] = min (dp[i],dp[i-1]);
        sol = max (sol,dp[i] * i);
    }

    cout<<sol;


    return 0;
}

Compilation message

bomb.cpp: In function 'int main()':
bomb.cpp:17:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   17 |         cin>>s+1;
      |              ~^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 620 KB Output is correct
3 Correct 30 ms 50540 KB Output is correct
4 Correct 30 ms 50540 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 620 KB Output is correct
9 Correct 1 ms 620 KB Output is correct
10 Correct 1 ms 620 KB Output is correct
11 Correct 1 ms 748 KB Output is correct
12 Correct 1 ms 620 KB Output is correct
13 Correct 1 ms 620 KB Output is correct
14 Correct 1 ms 620 KB Output is correct
15 Correct 1 ms 620 KB Output is correct
16 Correct 1 ms 748 KB Output is correct
17 Correct 2 ms 1644 KB Output is correct
18 Correct 1 ms 1260 KB Output is correct
19 Correct 2 ms 1792 KB Output is correct
20 Correct 2 ms 1644 KB Output is correct
21 Correct 2 ms 876 KB Output is correct
22 Correct 1 ms 1260 KB Output is correct
23 Correct 2 ms 1772 KB Output is correct
24 Correct 2 ms 1664 KB Output is correct
25 Correct 3 ms 2284 KB Output is correct
26 Correct 2 ms 2540 KB Output is correct
27 Correct 8 ms 7916 KB Output is correct
28 Correct 5 ms 2796 KB Output is correct
29 Correct 13 ms 10220 KB Output is correct
30 Correct 14 ms 8556 KB Output is correct
31 Correct 10 ms 6252 KB Output is correct
32 Correct 11 ms 8172 KB Output is correct
33 Correct 13 ms 10732 KB Output is correct
34 Correct 5 ms 3180 KB Output is correct
35 Correct 9 ms 4204 KB Output is correct
36 Correct 21 ms 13548 KB Output is correct
37 Correct 1 ms 748 KB Output is correct
38 Correct 676 ms 125164 KB Output is correct
39 Correct 1 ms 748 KB Output is correct
40 Correct 93 ms 33772 KB Output is correct
41 Correct 1 ms 748 KB Output is correct
42 Correct 2 ms 2540 KB Output is correct
43 Correct 584 ms 117400 KB Output is correct
44 Correct 16 ms 12268 KB Output is correct
45 Correct 568 ms 120020 KB Output is correct
46 Correct 544 ms 125160 KB Output is correct
47 Correct 563 ms 120172 KB Output is correct
48 Correct 536 ms 125072 KB Output is correct
49 Correct 677 ms 125136 KB Output is correct
50 Correct 544 ms 125036 KB Output is correct
51 Correct 541 ms 125036 KB Output is correct
52 Correct 540 ms 125036 KB Output is correct
53 Correct 535 ms 123756 KB Output is correct
54 Correct 451 ms 98412 KB Output is correct
55 Correct 463 ms 94956 KB Output is correct
56 Correct 657 ms 125148 KB Output is correct
57 Correct 424 ms 85100 KB Output is correct
58 Correct 437 ms 95084 KB Output is correct
59 Correct 428 ms 89068 KB Output is correct
60 Correct 507 ms 108740 KB Output is correct
61 Correct 667 ms 125292 KB Output is correct
62 Correct 679 ms 125420 KB Output is correct
63 Correct 680 ms 125420 KB Output is correct
64 Correct 430 ms 90988 KB Output is correct
65 Correct 547 ms 123116 KB Output is correct
66 Correct 563 ms 117176 KB Output is correct
67 Correct 575 ms 125396 KB Output is correct
68 Correct 592 ms 125292 KB Output is correct
69 Correct 440 ms 84596 KB Output is correct
70 Correct 233 ms 42476 KB Output is correct
71 Correct 416 ms 70380 KB Output is correct
72 Correct 418 ms 81496 KB Output is correct
73 Correct 443 ms 82540 KB Output is correct
74 Correct 429 ms 85684 KB Output is correct
75 Correct 433 ms 88812 KB Output is correct
76 Correct 440 ms 91500 KB Output is correct
77 Correct 449 ms 92396 KB Output is correct
78 Correct 449 ms 92908 KB Output is correct
79 Correct 311 ms 37740 KB Output is correct
80 Correct 312 ms 40300 KB Output is correct
81 Correct 327 ms 40940 KB Output is correct
82 Correct 452 ms 97644 KB Output is correct
83 Correct 453 ms 98028 KB Output is correct
84 Correct 309 ms 28396 KB Output is correct
85 Correct 437 ms 95724 KB Output is correct
86 Correct 627 ms 122988 KB Output is correct
87 Correct 436 ms 93548 KB Output is correct
88 Correct 450 ms 95468 KB Output is correct
89 Correct 505 ms 113004 KB Output is correct
90 Correct 280 ms 70636 KB Output is correct
91 Correct 460 ms 103404 KB Output is correct
92 Correct 497 ms 106732 KB Output is correct
93 Correct 617 ms 121164 KB Output is correct
94 Correct 526 ms 110616 KB Output is correct
95 Correct 452 ms 98056 KB Output is correct
96 Correct 454 ms 97388 KB Output is correct
97 Correct 652 ms 122476 KB Output is correct
98 Correct 458 ms 97004 KB Output is correct
99 Correct 518 ms 109804 KB Output is correct
100 Correct 635 ms 120300 KB Output is correct