Submission #170219

# Submission time Handle Problem Language Result Execution time Memory
170219 2019-12-24T09:23:25 Z theboatman Bomb (IZhO17_bomb) C++17
14 / 100
1000 ms 7616 KB
#include <bits/stdc++.h>

#define y1 theboatman
#define make_struct(args...) {args}

using namespace std;
typedef long long ll;

const long long INF = ll(1e18) + 10;
const int inf = int(1e9) + 10;
const int N = int(1e6) + 10;

bool can(int first, int c, int n, int m, vector <string> &a) {
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            if (a[i][j] == '1') {
                int sz = 0;
                while(j < m && a[i][j] == '1') {
                    j++;
                    sz++;
                }
                j--;

                if (sz < c) {
                    return false;
                }
            }
        }
    }

    for(int j = 0; j < m; j++) {
        for(int i = 0; i < n; i++) {
            if (a[i][j] == '1') {
                int sz = 0;
                while(i < n && a[i][j] == '1') {
                    i++;
                    sz++;
                }
                i--;

                if (sz < first) {
                    return false;
                }
            }
        }
    }

    return true;
}

void brute(int n, int m) {
    vector <string> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }

    ll ans = 0;
    for(int i = 1; i <= n; i++) {
        int first = i;

        if (!can(i, 1, n, m, a)) {
            continue;
        }

        int l = 1, r = m + 1;
        while(l < r) {
            int c = l + r >> 1;
            if (can(first, c, n, m, a)) {
                l = c + 1;
            }
            else {
                r = c;
            }
        }

        l--;
        ans = max(ans, 1LL * first * l);
    }
    cout << ans << "\n";
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);

    int n, m;
    cin >> n >> m;

    if (1LL * n * m * 5 <= int(5e7)) {
        brute(n, m);
        return 0;
    }

    vector <string> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }

    int second = m;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            if (a[i][j] == '1') {
                int sz = 0;
                while(j < m && a[i][j] == '1') {
                    j++;
                    sz++;
                }
                j--;

                second = min(second, sz);
            }
        }
    }

    int first = n;
    for(int j = 0; j < m; j++) {
        for(int i = 0; i < n; i++) {
            if (a[i][j] == '1') {
                int sz = 0;
                while(i < n && a[i][j] == '1') {
                    i++;
                    sz++;
                }
                i--;

                first = min(first, sz);
            }
        }
    }

    cout << 1LL * first * second << "\n";
    return 0;
}
/*
*/

Compilation message

bomb.cpp: In function 'void brute(int, int)':
bomb.cpp:67:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
             int c = l + r >> 1;
                     ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 22 ms 376 KB Output is correct
4 Correct 21 ms 504 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Incorrect 2 ms 376 KB Output isn't correct
9 Incorrect 2 ms 376 KB Output isn't correct
10 Incorrect 2 ms 376 KB Output isn't correct
11 Incorrect 2 ms 376 KB Output isn't correct
12 Incorrect 2 ms 376 KB Output isn't correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Incorrect 2 ms 376 KB Output isn't correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Incorrect 2 ms 376 KB Output isn't correct
19 Incorrect 4 ms 376 KB Output isn't correct
20 Incorrect 3 ms 376 KB Output isn't correct
21 Incorrect 2 ms 376 KB Output isn't correct
22 Incorrect 3 ms 376 KB Output isn't correct
23 Incorrect 5 ms 376 KB Output isn't correct
24 Incorrect 3 ms 376 KB Output isn't correct
25 Incorrect 5 ms 376 KB Output isn't correct
26 Correct 4 ms 504 KB Output is correct
27 Correct 26 ms 508 KB Output is correct
28 Incorrect 36 ms 504 KB Output isn't correct
29 Incorrect 214 ms 680 KB Output isn't correct
30 Incorrect 362 ms 748 KB Output isn't correct
31 Incorrect 91 ms 632 KB Output isn't correct
32 Incorrect 256 ms 632 KB Output isn't correct
33 Incorrect 420 ms 636 KB Output isn't correct
34 Incorrect 34 ms 504 KB Output isn't correct
35 Incorrect 133 ms 760 KB Output isn't correct
36 Correct 220 ms 760 KB Output is correct
37 Incorrect 2 ms 380 KB Output isn't correct
38 Execution timed out 1085 ms 7160 KB Time limit exceeded
39 Incorrect 2 ms 376 KB Output isn't correct
40 Execution timed out 1076 ms 1272 KB Time limit exceeded
41 Incorrect 2 ms 376 KB Output isn't correct
42 Incorrect 10 ms 376 KB Output isn't correct
43 Execution timed out 1079 ms 7160 KB Time limit exceeded
44 Incorrect 950 ms 732 KB Output isn't correct
45 Execution timed out 1075 ms 7160 KB Time limit exceeded
46 Execution timed out 1066 ms 7164 KB Time limit exceeded
47 Execution timed out 1056 ms 7160 KB Time limit exceeded
48 Execution timed out 1083 ms 7164 KB Time limit exceeded
49 Execution timed out 1068 ms 7160 KB Time limit exceeded
50 Execution timed out 1065 ms 7160 KB Time limit exceeded
51 Execution timed out 1079 ms 7160 KB Time limit exceeded
52 Execution timed out 1078 ms 7160 KB Time limit exceeded
53 Execution timed out 1077 ms 7160 KB Time limit exceeded
54 Execution timed out 1074 ms 7160 KB Time limit exceeded
55 Execution timed out 1086 ms 7160 KB Time limit exceeded
56 Execution timed out 1071 ms 7160 KB Time limit exceeded
57 Execution timed out 1084 ms 7160 KB Time limit exceeded
58 Execution timed out 1080 ms 7160 KB Time limit exceeded
59 Execution timed out 1079 ms 7160 KB Time limit exceeded
60 Execution timed out 1068 ms 7160 KB Time limit exceeded
61 Execution timed out 1072 ms 7288 KB Time limit exceeded
62 Execution timed out 1072 ms 7160 KB Time limit exceeded
63 Execution timed out 1074 ms 7160 KB Time limit exceeded
64 Execution timed out 1081 ms 7160 KB Time limit exceeded
65 Execution timed out 1075 ms 7160 KB Time limit exceeded
66 Execution timed out 1085 ms 7160 KB Time limit exceeded
67 Execution timed out 1075 ms 7160 KB Time limit exceeded
68 Execution timed out 1078 ms 7160 KB Time limit exceeded
69 Execution timed out 1060 ms 7160 KB Time limit exceeded
70 Execution timed out 1066 ms 4728 KB Time limit exceeded
71 Execution timed out 1075 ms 7160 KB Time limit exceeded
72 Execution timed out 1064 ms 7544 KB Time limit exceeded
73 Execution timed out 1077 ms 7516 KB Time limit exceeded
74 Execution timed out 1065 ms 7544 KB Time limit exceeded
75 Execution timed out 1055 ms 7544 KB Time limit exceeded
76 Execution timed out 1066 ms 7416 KB Time limit exceeded
77 Execution timed out 1072 ms 7616 KB Time limit exceeded
78 Execution timed out 1067 ms 7544 KB Time limit exceeded
79 Execution timed out 1058 ms 6984 KB Time limit exceeded
80 Execution timed out 1071 ms 7036 KB Time limit exceeded
81 Execution timed out 1078 ms 7032 KB Time limit exceeded
82 Execution timed out 1070 ms 7032 KB Time limit exceeded
83 Execution timed out 1078 ms 7032 KB Time limit exceeded
84 Execution timed out 1078 ms 7032 KB Time limit exceeded
85 Execution timed out 1076 ms 7032 KB Time limit exceeded
86 Execution timed out 1083 ms 7036 KB Time limit exceeded
87 Execution timed out 1081 ms 7032 KB Time limit exceeded
88 Execution timed out 1071 ms 7032 KB Time limit exceeded
89 Execution timed out 1071 ms 7032 KB Time limit exceeded
90 Execution timed out 1078 ms 4600 KB Time limit exceeded
91 Execution timed out 1088 ms 7032 KB Time limit exceeded
92 Execution timed out 1089 ms 7032 KB Time limit exceeded
93 Execution timed out 1080 ms 7032 KB Time limit exceeded
94 Execution timed out 1085 ms 7032 KB Time limit exceeded
95 Execution timed out 1083 ms 7032 KB Time limit exceeded
96 Execution timed out 1075 ms 7032 KB Time limit exceeded
97 Execution timed out 1085 ms 7004 KB Time limit exceeded
98 Execution timed out 1086 ms 7032 KB Time limit exceeded
99 Execution timed out 1086 ms 7036 KB Time limit exceeded
100 Execution timed out 1077 ms 7032 KB Time limit exceeded