Submission #704714

# Submission time Handle Problem Language Result Execution time Memory
704714 2023-03-02T18:09:45 Z KiriLL1ca Bomb (IZhO17_bomb) C++17
20 / 100
1000 ms 56436 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fr first
#define sc second
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define endl '\n'
#define sz(x) (int)((x).size())
#define vec vector
#define pw(x) (1ll << x)

using namespace std;
using namespace __gnu_pbds;

template <typename T> inline bool umin (T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
template <typename T> inline bool umax (T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;

inline void solve () {
    int n, m; cin >> n >> m;
    vector <string> a (n);
    for (auto &i : a) cin >> i;
    vector <vector <int>> p (n, vector <int> (m));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            if (i) p[i][j] += p[i - 1][j];
            if (j) p[i][j] += p[i][j - 1];
            if (i && j) p[i][j] -= p[i - 1][j - 1];
            p[i][j] += (a[i][j] - '0');
        }
    }

    auto get = [&] (int x, int y, int xx, int yy) {
        int res = p[xx][yy];
        if (x) res -= p[x - 1][yy];
        if (y) res -= p[xx][y - 1];
        if (x && y) res += p[x - 1][y - 1];
        return res;
    };

    int ans = 0;

    {
        int side = 1e9;
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < m; ++j) {
                int res = 0;
                for (int q = 12; ~q; --q) {
                    res += pw(q);
                    if (j + res - 1 >= m || get(i, j, i, j + res - 1) != res) res -= pw(q);
                }
                if (res) umin(side, res);
                j += res;
            }
        }

        auto bad = [&] (int t) {
            vector <vector <int>> f (n + 1, vector <int> (m + 1));

            for (int i = 0; i + t - 1 < n; ++i) {
                for (int j = 0; j + side - 1 < m; ++j) {
                    if (get(i, j, i + t - 1, j + side - 1) == side * t) {
                        ++f[i][j];
                        --f[i + t][j];
                        --f[i][j + side];
                        ++f[i + t][j + side];
                    }
                }
            }

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

            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < m; ++j) {
                    if (a[i][j] == '1' && !f[i][j]) return 1;
                }
            }
            return 0;
        };

        int res = 0;
        for (int i = 12; ~i; --i) {
            res += pw(i);
            if (bad(res)) res -= pw(i);
        }
        umax(ans, side * res);
    }

    {

        int side = 1e9;
        for (int j = 0; j < m; ++j) {
            for (int i = 0; i < n; ++i) {
                int res = 0;
                for (int q = 12; ~q; --q) {
                    res += pw(q);
                    if (i + res - 1 >= n || get(i, j, i + res - 1, j) != res) res -= pw(q);
                }
                if (res) umin(side, res);
                i += res;
            }
        }

        auto bad = [&] (int t) {
            vector <vector <int>> f (n + 1, vector <int> (m + 1));

            for (int i = 0; i + side - 1 < n; ++i) {
                for (int j = 0; j + t - 1 < m; ++j) {
                    if (get(i, j, i + side - 1, j + t - 1) == side * t) {
                        ++f[i][j];
                        --f[i + side][j];
                        --f[i][j + t];
                        ++f[i + side][j + t];
                    }
                }
            }

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

            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < m; ++j) {
                    if (a[i][j] == '1' && !f[i][j]) return 1;
                }
            }
            return 0;
        };

        int res = 0;
        for (int i = 12; ~i; --i) {
            res += pw(i);
            if (bad(res)) res -= pw(i);
        }
        umax(ans, side * res);
    }
    cout << ans;
}

signed main () {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif// LOCAL
    int t = 1; //cin >> t;
    while (t--) solve();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 6 ms 692 KB Output is correct
4 Correct 5 ms 576 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Incorrect 1 ms 212 KB Output isn't correct
9 Incorrect 1 ms 212 KB Output isn't correct
10 Correct 1 ms 212 KB Output is correct
11 Incorrect 1 ms 324 KB Output isn't correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Incorrect 1 ms 316 KB Output isn't correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Incorrect 2 ms 324 KB Output isn't correct
19 Incorrect 3 ms 340 KB Output isn't correct
20 Incorrect 3 ms 340 KB Output isn't correct
21 Incorrect 2 ms 340 KB Output isn't correct
22 Incorrect 2 ms 340 KB Output isn't correct
23 Incorrect 3 ms 340 KB Output isn't correct
24 Incorrect 2 ms 320 KB Output isn't correct
25 Incorrect 4 ms 340 KB Output isn't correct
26 Correct 3 ms 324 KB Output is correct
27 Correct 26 ms 1084 KB Output is correct
28 Incorrect 35 ms 1408 KB Output isn't correct
29 Incorrect 40 ms 1580 KB Output isn't correct
30 Incorrect 56 ms 2104 KB Output isn't correct
31 Incorrect 46 ms 1764 KB Output isn't correct
32 Incorrect 52 ms 1852 KB Output isn't correct
33 Incorrect 64 ms 2264 KB Output isn't correct
34 Incorrect 27 ms 1136 KB Output isn't correct
35 Incorrect 67 ms 2256 KB Output isn't correct
36 Correct 71 ms 2260 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Execution timed out 1085 ms 56352 KB Time limit exceeded
39 Correct 1 ms 212 KB Output is correct
40 Correct 190 ms 7364 KB Output is correct
41 Correct 1 ms 324 KB Output is correct
42 Incorrect 3 ms 340 KB Output isn't correct
43 Execution timed out 1092 ms 56308 KB Time limit exceeded
44 Incorrect 50 ms 2292 KB Output isn't correct
45 Execution timed out 1086 ms 56304 KB Time limit exceeded
46 Execution timed out 1079 ms 56320 KB Time limit exceeded
47 Execution timed out 1076 ms 56400 KB Time limit exceeded
48 Execution timed out 1040 ms 56264 KB Time limit exceeded
49 Execution timed out 1058 ms 56336 KB Time limit exceeded
50 Execution timed out 1063 ms 56308 KB Time limit exceeded
51 Execution timed out 1067 ms 56296 KB Time limit exceeded
52 Execution timed out 1082 ms 56308 KB Time limit exceeded
53 Execution timed out 1083 ms 56264 KB Time limit exceeded
54 Execution timed out 1087 ms 56316 KB Time limit exceeded
55 Execution timed out 1082 ms 56236 KB Time limit exceeded
56 Execution timed out 1063 ms 56300 KB Time limit exceeded
57 Execution timed out 1077 ms 56364 KB Time limit exceeded
58 Execution timed out 1071 ms 56300 KB Time limit exceeded
59 Execution timed out 1077 ms 56360 KB Time limit exceeded
60 Execution timed out 1086 ms 56340 KB Time limit exceeded
61 Execution timed out 1071 ms 56316 KB Time limit exceeded
62 Execution timed out 1084 ms 56264 KB Time limit exceeded
63 Execution timed out 1088 ms 56396 KB Time limit exceeded
64 Execution timed out 1093 ms 56308 KB Time limit exceeded
65 Execution timed out 1087 ms 56264 KB Time limit exceeded
66 Execution timed out 1075 ms 56276 KB Time limit exceeded
67 Execution timed out 1070 ms 56392 KB Time limit exceeded
68 Execution timed out 1075 ms 56300 KB Time limit exceeded
69 Execution timed out 1077 ms 56364 KB Time limit exceeded
70 Execution timed out 1086 ms 36168 KB Time limit exceeded
71 Execution timed out 1087 ms 56348 KB Time limit exceeded
72 Execution timed out 1086 ms 56240 KB Time limit exceeded
73 Execution timed out 1085 ms 56316 KB Time limit exceeded
74 Execution timed out 1037 ms 56236 KB Time limit exceeded
75 Execution timed out 1075 ms 56340 KB Time limit exceeded
76 Execution timed out 1080 ms 56396 KB Time limit exceeded
77 Execution timed out 1066 ms 56344 KB Time limit exceeded
78 Execution timed out 1083 ms 56276 KB Time limit exceeded
79 Execution timed out 1078 ms 56372 KB Time limit exceeded
80 Execution timed out 1075 ms 56368 KB Time limit exceeded
81 Execution timed out 1045 ms 56380 KB Time limit exceeded
82 Execution timed out 1084 ms 56236 KB Time limit exceeded
83 Execution timed out 1074 ms 56336 KB Time limit exceeded
84 Execution timed out 1076 ms 56436 KB Time limit exceeded
85 Execution timed out 1072 ms 56264 KB Time limit exceeded
86 Execution timed out 1069 ms 56268 KB Time limit exceeded
87 Execution timed out 1078 ms 56288 KB Time limit exceeded
88 Execution timed out 1073 ms 56260 KB Time limit exceeded
89 Execution timed out 1082 ms 56360 KB Time limit exceeded
90 Execution timed out 1083 ms 36128 KB Time limit exceeded
91 Execution timed out 1076 ms 56364 KB Time limit exceeded
92 Execution timed out 1071 ms 56396 KB Time limit exceeded
93 Execution timed out 1081 ms 56268 KB Time limit exceeded
94 Execution timed out 1082 ms 56284 KB Time limit exceeded
95 Execution timed out 1080 ms 56436 KB Time limit exceeded
96 Execution timed out 1074 ms 56292 KB Time limit exceeded
97 Execution timed out 1086 ms 56240 KB Time limit exceeded
98 Execution timed out 1085 ms 56288 KB Time limit exceeded
99 Execution timed out 1083 ms 56272 KB Time limit exceeded
100 Execution timed out 1083 ms 56116 KB Time limit exceeded