Submission #170980

# Submission time Handle Problem Language Result Execution time Memory
170980 2019-12-26T21:42:01 Z davitmarg Bomb (IZhO17_bomb) C++17
92 / 100
809 ms 74104 KB
/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
using namespace std;

const int N = 2505;

int n, m, a[N][N], nxt[N][N], lst[N][N], d[N], Y, X, ans;

int main()
{
    cin >> n >> m;

    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
        {
            char x;
            scanf(" %c", &x);
            a[i][j] += (x - '0');
        }
    X = m;
    Y = n;
    for (int i = 1; i <= n; i++)
    {
        for (int j = m; j >= 1; j--)
        {
            if (a[i][j])
                nxt[i][j] = nxt[i][j + 1] + 1;
            else
                nxt[i][j] = 0;
        }

        for (int j = 1; j <= m; j++)
            if (a[i][j])
                lst[i][j] = lst[i][j - 1] + 1;
            else
                lst[i][j] = 0;
    }

    for (int i = 1; i <= Y; i++)
        d[i] = X;

    for (int j = 1; j <= m; j++)
    {
        int y = 0, l = X, r = X;
        for (int i = 1; i <= n; i++)
        {
            if (a[i][j] == 0)
            {
                y = 0;
                l = r = X;
            }
            else
            {
                y++;
                r = min(r, nxt[i][j]);
                l = min(l, lst[i][j]);
                d[y] = min(l + r - 1, d[y]);
            }
            //cout << i << " : " << j << " = " << y << " : " << x << endl;
        }

        y = 0;
        l = X;
        r = X;
        for (int i = n; i >= 1; i--)
        {

            if (a[i][j] == 0)
            {
                y = 0;
                l = r = X;
            }
            else
            {
                y++;
                if (a[i - 1][j] == 0)
                    Y = min(y, Y);
                r = min(r, nxt[i][j]);
                l = min(l, lst[i][j]);
                d[y] = min(l + r - 1, d[y]);
            }
            //cout << i << " : " << j << " = " << y << " : " << x << endl;
        }
    }

    for (int i = 1; i <= Y; i++)
    {
        //d[i + 1] = min(d[i + 1], d[i]);
        //cout << i << " : " << d[i] << endl;
        ans = max(ans, i * d[i]);
    }

    cout << ans << endl;
    return 0;
}

/*

4 3
110
111
111
011

5 6
100000
111110
111110
111110
100000

6 5
00110
01110
11110
11011
11111
11111


9 9
000000000
000111000
000111000
011111110
011101110
011111110
000111000
000111000
000000000
 
9 9
000000000
000111000
000111000
011111110
011101110
011111110
000111000
000111000
000000000

6 6
000111
000111
001111
111100
111000
111000

6 6
000000
111000
111100
001111
000111
000111

6 6
000111
011111
011111
111000
111000
111000
 
*/

Compilation message

bomb.cpp: In function 'int main()':
bomb.cpp:38:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf(" %c", &x);
             ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 632 KB Output is correct
3 Correct 33 ms 30456 KB Output is correct
4 Correct 33 ms 30456 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Incorrect 2 ms 376 KB Output isn't correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 2 ms 504 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 2 ms 504 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 2 ms 504 KB Output is correct
14 Correct 2 ms 504 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
16 Correct 2 ms 632 KB Output is correct
17 Correct 3 ms 1144 KB Output is correct
18 Correct 3 ms 1272 KB Output is correct
19 Correct 3 ms 1528 KB Output is correct
20 Correct 3 ms 1528 KB Output is correct
21 Correct 3 ms 1016 KB Output is correct
22 Correct 3 ms 1400 KB Output is correct
23 Correct 3 ms 1656 KB Output is correct
24 Correct 3 ms 1400 KB Output is correct
25 Correct 3 ms 1656 KB Output is correct
26 Incorrect 4 ms 1656 KB Output isn't correct
27 Incorrect 11 ms 4856 KB Output isn't correct
28 Correct 12 ms 5112 KB Output is correct
29 Correct 15 ms 6520 KB Output is correct
30 Correct 19 ms 7672 KB Output is correct
31 Correct 15 ms 6136 KB Output is correct
32 Correct 16 ms 7032 KB Output is correct
33 Correct 20 ms 8056 KB Output is correct
34 Correct 10 ms 5496 KB Output is correct
35 Correct 19 ms 8184 KB Output is correct
36 Incorrect 24 ms 8184 KB Output isn't correct
37 Correct 2 ms 636 KB Output is correct
38 Correct 796 ms 73976 KB Output is correct
39 Correct 2 ms 636 KB Output is correct
40 Correct 92 ms 19960 KB Output is correct
41 Correct 2 ms 508 KB Output is correct
42 Correct 3 ms 1656 KB Output is correct
43 Correct 689 ms 73960 KB Output is correct
44 Correct 21 ms 8056 KB Output is correct
45 Correct 678 ms 73844 KB Output is correct
46 Correct 634 ms 73976 KB Output is correct
47 Correct 676 ms 73976 KB Output is correct
48 Correct 663 ms 74060 KB Output is correct
49 Incorrect 797 ms 74040 KB Output isn't correct
50 Correct 678 ms 73976 KB Output is correct
51 Correct 659 ms 73984 KB Output is correct
52 Correct 652 ms 73888 KB Output is correct
53 Correct 704 ms 73924 KB Output is correct
54 Correct 569 ms 74008 KB Output is correct
55 Correct 563 ms 73976 KB Output is correct
56 Correct 784 ms 73932 KB Output is correct
57 Correct 554 ms 74104 KB Output is correct
58 Correct 597 ms 73976 KB Output is correct
59 Correct 553 ms 73976 KB Output is correct
60 Correct 661 ms 73996 KB Output is correct
61 Incorrect 809 ms 73848 KB Output isn't correct
62 Incorrect 800 ms 73976 KB Output isn't correct
63 Incorrect 804 ms 73848 KB Output isn't correct
64 Correct 554 ms 73848 KB Output is correct
65 Correct 650 ms 74048 KB Output is correct
66 Correct 648 ms 73976 KB Output is correct
67 Correct 678 ms 74024 KB Output is correct
68 Correct 693 ms 74020 KB Output is correct
69 Correct 555 ms 74092 KB Output is correct
70 Correct 312 ms 59128 KB Output is correct
71 Correct 512 ms 73976 KB Output is correct
72 Correct 546 ms 74036 KB Output is correct
73 Correct 563 ms 73960 KB Output is correct
74 Correct 577 ms 73848 KB Output is correct
75 Correct 553 ms 73976 KB Output is correct
76 Correct 562 ms 73972 KB Output is correct
77 Correct 567 ms 73944 KB Output is correct
78 Correct 565 ms 73976 KB Output is correct
79 Correct 453 ms 73976 KB Output is correct
80 Correct 453 ms 73848 KB Output is correct
81 Correct 464 ms 74052 KB Output is correct
82 Correct 571 ms 73980 KB Output is correct
83 Correct 574 ms 73984 KB Output is correct
84 Correct 453 ms 73840 KB Output is correct
85 Correct 570 ms 73928 KB Output is correct
86 Correct 775 ms 74036 KB Output is correct
87 Correct 563 ms 73976 KB Output is correct
88 Correct 585 ms 73976 KB Output is correct
89 Correct 625 ms 74104 KB Output is correct
90 Correct 350 ms 59256 KB Output is correct
91 Correct 588 ms 73968 KB Output is correct
92 Correct 625 ms 73848 KB Output is correct
93 Correct 757 ms 73948 KB Output is correct
94 Correct 648 ms 73984 KB Output is correct
95 Correct 584 ms 73976 KB Output is correct
96 Correct 589 ms 73976 KB Output is correct
97 Correct 762 ms 73848 KB Output is correct
98 Correct 576 ms 73840 KB Output is correct
99 Correct 630 ms 74104 KB Output is correct
100 Correct 750 ms 73820 KB Output is correct