Submission #854581

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

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));
    vector<vector<int>> pref(n + 1, vector<int>(m + 1));
    for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) {
        cin >> a[i][j];
        pref[i][j] = pref[i][j - 1] + pref[i - 1][j] - pref[i - 1][j - 1] + (int) (a[i][j] == '1');
    }
    auto get_sum = [&](int x1, int y1, int x2, int y2) {
        return pref[x2][y2] - pref[x2][y1 - 1] - pref[x1 - 1][y2] + pref[x1 - 1][y1 - 1];
    };
    auto check = [&](int h, int w) {
        vector<vector<bool>> vis(n + 1, vector<bool>(m + 1));
        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 get_sum(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++) {
                            vis[x][y] = true;
                        }
                    }
                }
                if (!vis[i][j]) 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 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 6 ms 924 KB Output is correct
4 Correct 9 ms 916 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 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 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 6 ms 516 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 5 ms 516 KB Output is correct
26 Correct 22 ms 496 KB Output is correct
27 Correct 3 ms 860 KB Output is correct
28 Correct 3 ms 860 KB Output is correct
29 Execution timed out 1097 ms 1116 KB Time limit exceeded
30 Correct 335 ms 1432 KB Output is correct
31 Correct 398 ms 1116 KB Output is correct
32 Correct 126 ms 1272 KB Output is correct
33 Execution timed out 1018 ms 1368 KB Time limit exceeded
34 Correct 4 ms 856 KB Output is correct
35 Correct 24 ms 1372 KB Output is correct
36 Execution timed out 1050 ms 1368 KB Time limit exceeded
37 Correct 0 ms 348 KB Output is correct
38 Execution timed out 1088 ms 32004 KB Time limit exceeded
39 Correct 0 ms 344 KB Output is correct
40 Execution timed out 1037 ms 4312 KB Time limit exceeded
41 Correct 1 ms 344 KB Output is correct
42 Correct 191 ms 496 KB Output is correct
43 Execution timed out 1073 ms 32084 KB Time limit exceeded
44 Execution timed out 1057 ms 1384 KB Time limit exceeded
45 Execution timed out 1057 ms 31984 KB Time limit exceeded
46 Execution timed out 1050 ms 32556 KB Time limit exceeded
47 Execution timed out 1087 ms 32080 KB Time limit exceeded
48 Execution timed out 1025 ms 32144 KB Time limit exceeded
49 Execution timed out 1072 ms 32320 KB Time limit exceeded
50 Execution timed out 1058 ms 31988 KB Time limit exceeded
51 Execution timed out 1036 ms 32184 KB Time limit exceeded
52 Execution timed out 1010 ms 32240 KB Time limit exceeded
53 Execution timed out 1031 ms 32140 KB Time limit exceeded
54 Execution timed out 1051 ms 32124 KB Time limit exceeded
55 Execution timed out 1036 ms 32224 KB Time limit exceeded
56 Execution timed out 1071 ms 32220 KB Time limit exceeded
57 Execution timed out 1070 ms 32140 KB Time limit exceeded
58 Execution timed out 1061 ms 32140 KB Time limit exceeded
59 Execution timed out 1070 ms 32132 KB Time limit exceeded
60 Execution timed out 1031 ms 32140 KB Time limit exceeded
61 Execution timed out 1020 ms 32144 KB Time limit exceeded
62 Execution timed out 1020 ms 31984 KB Time limit exceeded
63 Execution timed out 1051 ms 32004 KB Time limit exceeded
64 Execution timed out 1082 ms 32140 KB Time limit exceeded
65 Execution timed out 1047 ms 32156 KB Time limit exceeded
66 Execution timed out 1035 ms 31988 KB Time limit exceeded
67 Execution timed out 1037 ms 32276 KB Time limit exceeded
68 Execution timed out 1059 ms 32004 KB Time limit exceeded
69 Execution timed out 1064 ms 32240 KB Time limit exceeded
70 Execution timed out 1042 ms 21012 KB Time limit exceeded
71 Execution timed out 1051 ms 32132 KB Time limit exceeded
72 Execution timed out 1014 ms 32132 KB Time limit exceeded
73 Execution timed out 1051 ms 32320 KB Time limit exceeded
74 Execution timed out 1055 ms 32320 KB Time limit exceeded
75 Execution timed out 1061 ms 32248 KB Time limit exceeded
76 Execution timed out 1035 ms 32284 KB Time limit exceeded
77 Execution timed out 1048 ms 32204 KB Time limit exceeded
78 Execution timed out 1014 ms 32080 KB Time limit exceeded
79 Execution timed out 1050 ms 32576 KB Time limit exceeded
80 Execution timed out 1066 ms 32372 KB Time limit exceeded
81 Execution timed out 1044 ms 32344 KB Time limit exceeded
82 Execution timed out 1063 ms 32352 KB Time limit exceeded
83 Execution timed out 1056 ms 32180 KB Time limit exceeded
84 Correct 284 ms 32160 KB Output is correct
85 Execution timed out 1082 ms 32084 KB Time limit exceeded
86 Execution timed out 1048 ms 32084 KB Time limit exceeded
87 Execution timed out 1057 ms 32132 KB Time limit exceeded
88 Execution timed out 1048 ms 32324 KB Time limit exceeded
89 Execution timed out 1097 ms 32080 KB Time limit exceeded
90 Execution timed out 1040 ms 20788 KB Time limit exceeded
91 Execution timed out 1069 ms 32136 KB Time limit exceeded
92 Execution timed out 1083 ms 32056 KB Time limit exceeded
93 Execution timed out 1034 ms 32132 KB Time limit exceeded
94 Execution timed out 1050 ms 31988 KB Time limit exceeded
95 Execution timed out 1075 ms 32136 KB Time limit exceeded
96 Execution timed out 1070 ms 32132 KB Time limit exceeded
97 Execution timed out 1045 ms 32120 KB Time limit exceeded
98 Execution timed out 1066 ms 32136 KB Time limit exceeded
99 Execution timed out 1036 ms 32084 KB Time limit exceeded
100 Execution timed out 1059 ms 32148 KB Time limit exceeded