Submission #366876

# Submission time Handle Problem Language Result Execution time Memory
366876 2021-02-15T15:13:04 Z Ruxandra985 Bomb (IZhO17_bomb) C++14
3 / 100
537 ms 67968 KB
#include <bits/stdc++.h>

using namespace std;
char a[2510][2510] , b[2510][2510];
int sl[2510][2510] , sr[2510][2510] , v[2510];
int dp[2510] , n , m;

void solve (){
    int i , j , minil , minir , last;

    for (i = 1 ; i <= n ; i++){
        for (j = 1 ; j <= m ; j++)
            sl[i][j] = sr[i][j] = 0;
    }

    for (i = 1 ; i <= n ; i++){
        for (j = 1 ; j <= m ; j++){
            if (a[i][j] == '1'){
                sl[i][j] = 1 + sl[i][j - 1];
                if (a[i][j + 1] != '1')
                    dp[1] = min(dp[1] , sl[i][j]);
                /// daca am o linie, pot sa am dp[1] coloane
            }
        }
        for (j = m ; j ; j--){
            if (a[i][j] == '1')
                sr[i][j] = 1 + sr[i][j + 1];
        }
    }

    /// ce se intampla daca vreau mai mult de o linie

    for (j = 1 ; j <= m ; j++){
        minil = minir = 2000000000;
        last = 0;
        for (i = 0 ; i <= n + 1 ; i++){

            if (a[i][j] != '1'){
                if (last && i - last != 1)
                    dp[i - last] = 0; /// nu poti sa ai atatea linii
                last = i; /// utlima linie pe care e 0 pe pozitia asta
                minil = minir = 2000000000;
            }
            else {
                minir = min(minir , sr[i][j]);
                minil = min(minil , sl[i][j]);
                dp[i - last] = min(dp[i - last] , minil + minir - 1);
            }


        }
    }

    for (i = 2 ; i <= n ; i++)
        dp[i] = min (dp[i] , dp[i - 1]);

    //printf ("%d ",dp[1]);

}

int main()
{
    FILE *fin = stdin;
    FILE *fout = stdout;
    int i , j , miniw , minih , lenc , sol;
    fscanf (fin,"%d%d\n",&n,&m);
    for (i = 1 ; i <= n ; i++){
        for (j = 1 ; j <= m ; j++)
            a[i][j] = fgetc(fin);
        fgetc(fin);
    }

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

    sol = 0;

    solve();

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

    for (i = 1 ; i <= n ; i++){
        for (j = 1 ; j <= m ; j++){
            a[i][j] = b[i][j];
        }
    }

    solve();
    for (i = 1 ; i <= n ; i++){
        if (dp[i] != 2000000000)
            sol = max(sol , i * dp[i]);
    }
    fprintf (fout,"%d",sol);

    /// raspuns

    return 0;
}

Compilation message

bomb.cpp: In function 'int main()':
bomb.cpp:65:17: warning: unused variable 'miniw' [-Wunused-variable]
   65 |     int i , j , miniw , minih , lenc , sol;
      |                 ^~~~~
bomb.cpp:65:25: warning: unused variable 'minih' [-Wunused-variable]
   65 |     int i , j , miniw , minih , lenc , sol;
      |                         ^~~~~
bomb.cpp:65:33: warning: unused variable 'lenc' [-Wunused-variable]
   65 |     int i , j , miniw , minih , lenc , sol;
      |                                 ^~~~
bomb.cpp:66:12: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   66 |     fscanf (fin,"%d%d\n",&n,&m);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 620 KB Output isn't correct
3 Incorrect 18 ms 32748 KB Output isn't correct
4 Incorrect 17 ms 32748 KB Output isn't correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Incorrect 1 ms 364 KB Output isn't correct
8 Incorrect 1 ms 620 KB Output isn't correct
9 Incorrect 1 ms 620 KB Output isn't correct
10 Incorrect 1 ms 492 KB Output isn't correct
11 Incorrect 1 ms 620 KB Output isn't correct
12 Incorrect 1 ms 492 KB Output isn't correct
13 Incorrect 1 ms 492 KB Output isn't correct
14 Incorrect 1 ms 492 KB Output isn't correct
15 Incorrect 1 ms 620 KB Output isn't correct
16 Incorrect 1 ms 620 KB Output isn't correct
17 Incorrect 1 ms 1260 KB Output isn't correct
18 Incorrect 2 ms 1260 KB Output isn't correct
19 Incorrect 1 ms 1644 KB Output isn't correct
20 Incorrect 1 ms 1644 KB Output isn't correct
21 Incorrect 1 ms 1148 KB Output isn't correct
22 Incorrect 1 ms 1388 KB Output isn't correct
23 Incorrect 2 ms 1772 KB Output isn't correct
24 Incorrect 1 ms 1388 KB Output isn't correct
25 Incorrect 1 ms 1772 KB Output isn't correct
26 Incorrect 2 ms 1772 KB Output isn't correct
27 Incorrect 5 ms 4844 KB Output isn't correct
28 Incorrect 5 ms 5100 KB Output isn't correct
29 Incorrect 9 ms 6508 KB Output isn't correct
30 Incorrect 17 ms 7532 KB Output isn't correct
31 Incorrect 7 ms 5996 KB Output isn't correct
32 Incorrect 7 ms 7020 KB Output isn't correct
33 Incorrect 9 ms 7936 KB Output isn't correct
34 Incorrect 5 ms 5612 KB Output isn't correct
35 Incorrect 8 ms 7916 KB Output isn't correct
36 Incorrect 12 ms 7916 KB Output isn't correct
37 Incorrect 1 ms 620 KB Output isn't correct
38 Incorrect 537 ms 67688 KB Output isn't correct
39 Incorrect 1 ms 620 KB Output isn't correct
40 Incorrect 71 ms 18412 KB Output isn't correct
41 Incorrect 1 ms 620 KB Output isn't correct
42 Incorrect 2 ms 1792 KB Output isn't correct
43 Incorrect 428 ms 67676 KB Output isn't correct
44 Incorrect 10 ms 7916 KB Output isn't correct
45 Incorrect 402 ms 67564 KB Output isn't correct
46 Incorrect 386 ms 67564 KB Output isn't correct
47 Incorrect 416 ms 67564 KB Output isn't correct
48 Incorrect 371 ms 67564 KB Output isn't correct
49 Incorrect 525 ms 67564 KB Output isn't correct
50 Incorrect 380 ms 67556 KB Output isn't correct
51 Incorrect 396 ms 67968 KB Output isn't correct
52 Incorrect 381 ms 67564 KB Output isn't correct
53 Incorrect 371 ms 67664 KB Output isn't correct
54 Incorrect 289 ms 67436 KB Output isn't correct
55 Incorrect 286 ms 67564 KB Output isn't correct
56 Incorrect 497 ms 67564 KB Output isn't correct
57 Incorrect 269 ms 67436 KB Output isn't correct
58 Incorrect 278 ms 67436 KB Output isn't correct
59 Incorrect 271 ms 67436 KB Output isn't correct
60 Incorrect 349 ms 67564 KB Output isn't correct
61 Incorrect 495 ms 67812 KB Output isn't correct
62 Incorrect 489 ms 67676 KB Output isn't correct
63 Incorrect 504 ms 67564 KB Output isn't correct
64 Incorrect 274 ms 67564 KB Output isn't correct
65 Incorrect 365 ms 67820 KB Output isn't correct
66 Incorrect 337 ms 67820 KB Output isn't correct
67 Incorrect 365 ms 67692 KB Output isn't correct
68 Incorrect 371 ms 67692 KB Output isn't correct
69 Incorrect 255 ms 67564 KB Output isn't correct
70 Incorrect 136 ms 53356 KB Output isn't correct
71 Incorrect 220 ms 67564 KB Output isn't correct
72 Incorrect 251 ms 67564 KB Output isn't correct
73 Incorrect 256 ms 67436 KB Output isn't correct
74 Incorrect 251 ms 67436 KB Output isn't correct
75 Incorrect 259 ms 67436 KB Output isn't correct
76 Incorrect 285 ms 67564 KB Output isn't correct
77 Incorrect 285 ms 67564 KB Output isn't correct
78 Incorrect 281 ms 67564 KB Output isn't correct
79 Incorrect 165 ms 67436 KB Output isn't correct
80 Incorrect 179 ms 67308 KB Output isn't correct
81 Incorrect 176 ms 67436 KB Output isn't correct
82 Incorrect 303 ms 67564 KB Output isn't correct
83 Incorrect 297 ms 67564 KB Output isn't correct
84 Incorrect 180 ms 67624 KB Output isn't correct
85 Incorrect 284 ms 67564 KB Output isn't correct
86 Incorrect 459 ms 67564 KB Output isn't correct
87 Incorrect 248 ms 67436 KB Output isn't correct
88 Incorrect 278 ms 67436 KB Output isn't correct
89 Incorrect 303 ms 67564 KB Output isn't correct
90 Incorrect 181 ms 53356 KB Output isn't correct
91 Incorrect 316 ms 67564 KB Output isn't correct
92 Incorrect 341 ms 67820 KB Output isn't correct
93 Incorrect 457 ms 67692 KB Output isn't correct
94 Incorrect 331 ms 67564 KB Output isn't correct
95 Incorrect 305 ms 67564 KB Output isn't correct
96 Incorrect 312 ms 67564 KB Output isn't correct
97 Incorrect 475 ms 67692 KB Output isn't correct
98 Incorrect 307 ms 67564 KB Output isn't correct
99 Incorrect 331 ms 67692 KB Output isn't correct
100 Incorrect 414 ms 67692 KB Output isn't correct