Submission #854585

# Submission time Handle Problem Language Result Execution time Memory
854585 2023-09-28T06:16:14 Z The_Samurai Bomb (IZhO17_bomb) C++17
38 / 100
1000 ms 55892 KB
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
const int inf = 1e9, N = 1e6 + 5;

struct Fenwick_2d {
    vector<vector<int>> tree;
    int l1, l2;

    void init(int n, int m) {
        l1 = n; l2 = m;
        tree.assign(l1 + 1, vector<int>(l2 + 1, 0));
    }

    void update(int x, int y, int v) {
        x++; y++;
        for (; x <= l1; x += x & (-x)) {
            for (int yy = y; yy <= l2; yy += yy & (-yy)) {
                tree[x][yy] += v;
            }
        }
    }

    int get(int x, int y) {
        x++; y++;
        int sum = 0;
        for (; x > 0; x -= x & (-x)) {
            for (int yy = y; yy > 0; yy -= yy & (-yy)) {
                sum += tree[x][yy];
            }
        }
        return sum;
    }

    int get(int x1, int y1, int x2, int y2) {
        return get(x2, y2) - get(x2, y1 - 1) - get(x1 - 1, y2) + get(x1 - 1, y1 - 1);
    }
};

int main() {
    cin.tie(0)->sync_with_stdio(false);
#ifdef sunnatov
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
//    freopen("game.in", "r", stdin);
//    freopen("game.out", "w", stdout);
#endif

    int n, m;
    cin >> n >> m;
    vector<vector<char>> a(n + 1, vector<char>(m + 1));
    Fenwick_2d fw; fw.init(n + 1, m + 1);
    for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) {
        cin >> a[i][j];
        if (a[i][j] == '1') fw.update(i, j, 1);
    }
    vector<vector<int>> checked(n + 1, vector<int>(m + 1));
    int z = 0;
    auto check = [&](int h, int w) {
        z++;
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                if (a[i][j] == '0') continue;
                if (i + h - 1 <= n and j + w - 1 <= m and fw.get(i, j, i + h - 1, j + w - 1) == h * w) {
                    for (int x = i; x < i + h; x++) {
                        for (int y = j; y < j + w; y++) {
                            checked[x][y] = z;
                        }
                    }
                }
                if (checked[i][j] < z) return false;
            }
        }
        return true;
    };
    vector<int> best(n + 1, -1);
    auto get = [&](int h) {
        if (best[h] != -1) return best[h];
        int lx = 1, rx = (h > 1 ? best[h - 1] : m);
        best[h] = 0;
        while (lx <= rx) {
            int mid = (lx + rx) >> 1;
            if (check(h, mid)) {
                best[h] = mid;
                lx = mid + 1;
            } else {
                rx = mid - 1;
            }
        }
        return best[h];
    };
    int ans = 0;
    for (int i = 1; i <= n; i++) ans = max(ans, get(i) * i);
    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 7 ms 876 KB Output is correct
4 Correct 8 ms 860 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 424 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 356 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 2 ms 344 KB Output is correct
20 Correct 2 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 10 ms 556 KB Output is correct
24 Correct 2 ms 520 KB Output is correct
25 Correct 14 ms 556 KB Output is correct
26 Correct 32 ms 348 KB Output is correct
27 Correct 13 ms 1192 KB Output is correct
28 Correct 3 ms 1372 KB Output is correct
29 Execution timed out 1085 ms 1372 KB Time limit exceeded
30 Correct 610 ms 2392 KB Output is correct
31 Correct 473 ms 1628 KB Output is correct
32 Correct 274 ms 1880 KB Output is correct
33 Execution timed out 1059 ms 2140 KB Time limit exceeded
34 Correct 4 ms 1116 KB Output is correct
35 Correct 30 ms 2136 KB Output is correct
36 Execution timed out 1067 ms 2140 KB Time limit exceeded
37 Correct 0 ms 348 KB Output is correct
38 Execution timed out 1092 ms 55568 KB Time limit exceeded
39 Correct 1 ms 344 KB Output is correct
40 Execution timed out 1044 ms 7260 KB Time limit exceeded
41 Correct 0 ms 348 KB Output is correct
42 Correct 118 ms 348 KB Output is correct
43 Execution timed out 1054 ms 55544 KB Time limit exceeded
44 Execution timed out 1063 ms 2140 KB Time limit exceeded
45 Execution timed out 1062 ms 55544 KB Time limit exceeded
46 Execution timed out 1069 ms 55552 KB Time limit exceeded
47 Execution timed out 1071 ms 55636 KB Time limit exceeded
48 Execution timed out 1070 ms 55636 KB Time limit exceeded
49 Execution timed out 1070 ms 55548 KB Time limit exceeded
50 Execution timed out 1064 ms 55636 KB Time limit exceeded
51 Execution timed out 1064 ms 55552 KB Time limit exceeded
52 Execution timed out 1042 ms 55636 KB Time limit exceeded
53 Execution timed out 1025 ms 55560 KB Time limit exceeded
54 Execution timed out 1040 ms 55548 KB Time limit exceeded
55 Execution timed out 1052 ms 55544 KB Time limit exceeded
56 Execution timed out 1046 ms 55632 KB Time limit exceeded
57 Execution timed out 1077 ms 55560 KB Time limit exceeded
58 Execution timed out 1100 ms 55548 KB Time limit exceeded
59 Execution timed out 1055 ms 55552 KB Time limit exceeded
60 Execution timed out 1058 ms 55548 KB Time limit exceeded
61 Execution timed out 1045 ms 55552 KB Time limit exceeded
62 Execution timed out 1076 ms 55548 KB Time limit exceeded
63 Execution timed out 1043 ms 55632 KB Time limit exceeded
64 Execution timed out 1069 ms 55640 KB Time limit exceeded
65 Execution timed out 1069 ms 55636 KB Time limit exceeded
66 Execution timed out 1047 ms 55560 KB Time limit exceeded
67 Execution timed out 1060 ms 55560 KB Time limit exceeded
68 Execution timed out 1074 ms 55636 KB Time limit exceeded
69 Execution timed out 1074 ms 55636 KB Time limit exceeded
70 Execution timed out 1048 ms 35924 KB Time limit exceeded
71 Execution timed out 1076 ms 55548 KB Time limit exceeded
72 Execution timed out 1040 ms 55548 KB Time limit exceeded
73 Execution timed out 1059 ms 55572 KB Time limit exceeded
74 Execution timed out 1032 ms 55632 KB Time limit exceeded
75 Execution timed out 1040 ms 55548 KB Time limit exceeded
76 Execution timed out 1034 ms 55632 KB Time limit exceeded
77 Execution timed out 1053 ms 55556 KB Time limit exceeded
78 Execution timed out 1061 ms 55544 KB Time limit exceeded
79 Execution timed out 1102 ms 55544 KB Time limit exceeded
80 Execution timed out 1070 ms 55548 KB Time limit exceeded
81 Execution timed out 1059 ms 55636 KB Time limit exceeded
82 Execution timed out 1071 ms 55636 KB Time limit exceeded
83 Execution timed out 1064 ms 55552 KB Time limit exceeded
84 Correct 283 ms 55892 KB Output is correct
85 Execution timed out 1074 ms 55632 KB Time limit exceeded
86 Execution timed out 1066 ms 55636 KB Time limit exceeded
87 Execution timed out 1055 ms 55568 KB Time limit exceeded
88 Execution timed out 1028 ms 55632 KB Time limit exceeded
89 Execution timed out 1066 ms 55636 KB Time limit exceeded
90 Execution timed out 1037 ms 35804 KB Time limit exceeded
91 Execution timed out 1035 ms 55632 KB Time limit exceeded
92 Execution timed out 1080 ms 55632 KB Time limit exceeded
93 Execution timed out 1067 ms 55892 KB Time limit exceeded
94 Execution timed out 1057 ms 55552 KB Time limit exceeded
95 Execution timed out 1072 ms 55564 KB Time limit exceeded
96 Execution timed out 1042 ms 55552 KB Time limit exceeded
97 Execution timed out 1037 ms 55632 KB Time limit exceeded
98 Execution timed out 1044 ms 55544 KB Time limit exceeded
99 Execution timed out 1078 ms 55636 KB Time limit exceeded
100 Execution timed out 1012 ms 55812 KB Time limit exceeded