Submission #1010985

# Submission time Handle Problem Language Result Execution time Memory
1010985 2024-06-29T16:17:48 Z LucaIlie Bomb (IZhO17_bomb) C++17
21 / 100
1000 ms 77392 KB
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 2500;
int mat[MAX_N + 2][MAX_N + 2], up[MAX_N + 2][MAX_N + 2], down[MAX_N + 2][MAX_N + 2], hup[MAX_N + 2], hdown[MAX_N + 2], maxHeight[MAX_N + 2];

int main() {
    int n, m;

    cin >> n >> m;
    for ( int l = 1; l <= n; l++ ) {
        for ( int c = 1; c <= m; c++ ) {
            char ch;
            cin >> ch;
            mat[l][c] = ch - '0';
        }
    }

    for ( int l = 1; l <= n; l++ ) {
        for ( int c = 1; c <= m; c++ )
            up[l][c] = (mat[l][c] ? up[l - 1][c] + 1 : 0);
    }
    for ( int l = n; l >= 1; l-- ) {
        for ( int c = 1; c <= m; c++ )
            down[l][c] = (mat[l][c] ? down[l + 1][c] + 1 : 0);
    }

    int maxArea = 0;
    for ( int w = 1; w <= m; w++ ) {
        int h = n;
        for ( int l = 0; l <= n; l++ ) {
            //printf( "LINE %d:\n", l );
            deque<int> dq;
            for ( int c = 1; c <= m; c++ ) {
                if ( !dq.empty() && dq.front() <= c - w )
                    dq.pop_front();
                while ( !dq.empty() && up[l][c] <= up[l][dq.back()] )
                    dq.pop_back();
                dq.push_back( c );
                hup[c] = up[l][dq.front()];
            }
            while ( !dq.empty() )
                dq.pop_back();

            for ( int c = 1; c <= m; c++ ) {
                if ( !dq.empty() && dq.front() <= c - w )
                    dq.pop_front();
                while ( !dq.empty() && down[l + 1][c] <= down[l + 1][dq.back()] )
                    dq.pop_back();
                dq.push_back( c );
                hdown[c] = down[l + 1][dq.front()];
            }
            while ( !dq.empty() )
                dq.pop_back();

            //for ( int c = 1; c <= m; c++ )
                //printf( "%d ", hup[c] );
            //printf( "\n" );
            //for ( int c = 1; c <= m; c++ )
                //printf( "%d ", hdown[c] );
            //printf( "\n" );

            for ( int c = m; c >= 1; c-- ) {
                if ( !dq.empty() && dq.front() >= c + w )
                    dq.pop_front();
                if ( c >= w ) {
                    while ( !dq.empty() && hdown[c] + hup[c] >= hdown[dq.back()] + hup[dq.back()] )
                        dq.pop_back();
                    dq.push_back( c );
                }
                if ( !dq.empty() )
                    maxHeight[c] = hdown[dq.front()] + hup[dq.front()];
                else
                    maxHeight[c] = n;
            }

            for ( int c = 1; c <= m; c++ ) {
                if ( mat[l][c] )
                    h = min( h, maxHeight[c] );
                //printf( "%d ", mat[l][c] ? maxHeight[c] : 9 );
            }
            //printf( "\n" );
        }

        //printf( "\n\n\n\nBA AVEM W SI H!!!!!!!!!!! %d %d\n\n\n", w, h );

        maxArea = max( maxArea, w * h );
    }

    cout << maxArea;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 10 ms 30556 KB Output is correct
4 Correct 10 ms 30556 KB Output is correct
5 Correct 118 ms 492 KB Output is correct
6 Correct 18 ms 344 KB Output is correct
7 Incorrect 0 ms 348 KB Output isn't correct
8 Incorrect 0 ms 604 KB Output isn't correct
9 Incorrect 1 ms 604 KB Output isn't correct
10 Incorrect 1 ms 604 KB Output isn't correct
11 Correct 0 ms 604 KB Output is correct
12 Incorrect 1 ms 600 KB Output isn't correct
13 Correct 0 ms 604 KB Output is correct
14 Correct 0 ms 604 KB Output is correct
15 Incorrect 1 ms 604 KB Output isn't correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 5 ms 1116 KB Output is correct
18 Incorrect 4 ms 1116 KB Output isn't correct
19 Incorrect 7 ms 1628 KB Output isn't correct
20 Incorrect 7 ms 1624 KB Output isn't correct
21 Incorrect 4 ms 1116 KB Output isn't correct
22 Incorrect 8 ms 1372 KB Output isn't correct
23 Correct 11 ms 1628 KB Output is correct
24 Correct 5 ms 1372 KB Output is correct
25 Incorrect 11 ms 1780 KB Output isn't correct
26 Incorrect 12 ms 1628 KB Output isn't correct
27 Incorrect 262 ms 4700 KB Output isn't correct
28 Incorrect 384 ms 5212 KB Output isn't correct
29 Incorrect 435 ms 6496 KB Output isn't correct
30 Correct 753 ms 7772 KB Output is correct
31 Correct 650 ms 6232 KB Output is correct
32 Correct 547 ms 7004 KB Output is correct
33 Incorrect 858 ms 8240 KB Output isn't correct
34 Incorrect 185 ms 5692 KB Output isn't correct
35 Incorrect 822 ms 8240 KB Output isn't correct
36 Incorrect 958 ms 8024 KB Output isn't correct
37 Correct 0 ms 600 KB Output is correct
38 Execution timed out 1099 ms 73812 KB Time limit exceeded
39 Correct 1 ms 600 KB Output is correct
40 Execution timed out 1042 ms 20120 KB Time limit exceeded
41 Correct 1 ms 604 KB Output is correct
42 Correct 12 ms 1788 KB Output is correct
43 Execution timed out 1086 ms 73812 KB Time limit exceeded
44 Correct 925 ms 8024 KB Output is correct
45 Execution timed out 1098 ms 77188 KB Time limit exceeded
46 Execution timed out 1064 ms 77012 KB Time limit exceeded
47 Execution timed out 1052 ms 77140 KB Time limit exceeded
48 Execution timed out 1067 ms 77084 KB Time limit exceeded
49 Execution timed out 1047 ms 77096 KB Time limit exceeded
50 Execution timed out 1060 ms 77192 KB Time limit exceeded
51 Execution timed out 1022 ms 77392 KB Time limit exceeded
52 Execution timed out 1022 ms 77180 KB Time limit exceeded
53 Execution timed out 1016 ms 77084 KB Time limit exceeded
54 Execution timed out 1068 ms 77196 KB Time limit exceeded
55 Execution timed out 1060 ms 77028 KB Time limit exceeded
56 Execution timed out 1060 ms 77236 KB Time limit exceeded
57 Execution timed out 1067 ms 77060 KB Time limit exceeded
58 Execution timed out 1055 ms 77132 KB Time limit exceeded
59 Execution timed out 1043 ms 77140 KB Time limit exceeded
60 Execution timed out 1045 ms 77096 KB Time limit exceeded
61 Execution timed out 1028 ms 77168 KB Time limit exceeded
62 Execution timed out 1026 ms 77136 KB Time limit exceeded
63 Execution timed out 1031 ms 77136 KB Time limit exceeded
64 Execution timed out 1036 ms 77036 KB Time limit exceeded
65 Execution timed out 1014 ms 77136 KB Time limit exceeded
66 Execution timed out 1038 ms 77256 KB Time limit exceeded
67 Execution timed out 1064 ms 77340 KB Time limit exceeded
68 Execution timed out 1036 ms 77136 KB Time limit exceeded
69 Execution timed out 1034 ms 77072 KB Time limit exceeded
70 Execution timed out 1016 ms 63056 KB Time limit exceeded
71 Execution timed out 1069 ms 77192 KB Time limit exceeded
72 Execution timed out 1067 ms 77152 KB Time limit exceeded
73 Execution timed out 1049 ms 77008 KB Time limit exceeded
74 Execution timed out 1067 ms 77140 KB Time limit exceeded
75 Execution timed out 1044 ms 77136 KB Time limit exceeded
76 Execution timed out 1029 ms 77200 KB Time limit exceeded
77 Execution timed out 1050 ms 77140 KB Time limit exceeded
78 Execution timed out 1008 ms 77152 KB Time limit exceeded
79 Execution timed out 1016 ms 77188 KB Time limit exceeded
80 Execution timed out 1056 ms 77140 KB Time limit exceeded
81 Execution timed out 1093 ms 77172 KB Time limit exceeded
82 Execution timed out 1022 ms 77136 KB Time limit exceeded
83 Execution timed out 1059 ms 77140 KB Time limit exceeded
84 Execution timed out 1049 ms 76996 KB Time limit exceeded
85 Execution timed out 1058 ms 77076 KB Time limit exceeded
86 Execution timed out 1055 ms 77176 KB Time limit exceeded
87 Execution timed out 1090 ms 77092 KB Time limit exceeded
88 Execution timed out 1022 ms 77220 KB Time limit exceeded
89 Execution timed out 1052 ms 77140 KB Time limit exceeded
90 Execution timed out 1099 ms 66748 KB Time limit exceeded
91 Execution timed out 1086 ms 77152 KB Time limit exceeded
92 Execution timed out 1025 ms 77132 KB Time limit exceeded
93 Execution timed out 1008 ms 77016 KB Time limit exceeded
94 Execution timed out 1020 ms 77136 KB Time limit exceeded
95 Execution timed out 1025 ms 77136 KB Time limit exceeded
96 Execution timed out 1056 ms 77052 KB Time limit exceeded
97 Execution timed out 1103 ms 77108 KB Time limit exceeded
98 Execution timed out 1020 ms 77096 KB Time limit exceeded
99 Execution timed out 1031 ms 77140 KB Time limit exceeded
100 Execution timed out 1058 ms 77144 KB Time limit exceeded