답안 #704713

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
704713 2023-03-02T18:08:37 Z KiriLL1ca Bomb (IZhO17_bomb) C++17
23 / 100
1000 ms 56464 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)

#pragma GCC optimize ("Ofast")

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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 3 ms 596 KB Output is correct
4 Correct 4 ms 596 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Incorrect 0 ms 212 KB Output isn't correct
9 Incorrect 0 ms 212 KB Output isn't correct
10 Correct 0 ms 212 KB Output is correct
11 Incorrect 0 ms 212 KB Output isn't correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Incorrect 0 ms 212 KB Output isn't correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Incorrect 1 ms 340 KB Output isn't correct
19 Incorrect 1 ms 340 KB Output isn't correct
20 Incorrect 1 ms 340 KB Output isn't correct
21 Incorrect 1 ms 340 KB Output isn't correct
22 Incorrect 2 ms 340 KB Output isn't correct
23 Incorrect 2 ms 340 KB Output isn't correct
24 Incorrect 1 ms 340 KB Output isn't correct
25 Incorrect 2 ms 384 KB Output isn't correct
26 Correct 2 ms 340 KB Output is correct
27 Correct 14 ms 1044 KB Output is correct
28 Incorrect 22 ms 1300 KB Output isn't correct
29 Incorrect 22 ms 1468 KB Output isn't correct
30 Incorrect 36 ms 2032 KB Output isn't correct
31 Incorrect 29 ms 1772 KB Output isn't correct
32 Incorrect 30 ms 1816 KB Output isn't correct
33 Incorrect 38 ms 2164 KB Output isn't correct
34 Incorrect 19 ms 1092 KB Output isn't correct
35 Incorrect 42 ms 2180 KB Output isn't correct
36 Correct 40 ms 2164 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 856 ms 56200 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 118 ms 7324 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Incorrect 2 ms 340 KB Output isn't correct
43 Execution timed out 1089 ms 56296 KB Time limit exceeded
44 Incorrect 32 ms 2164 KB Output isn't correct
45 Execution timed out 1096 ms 56244 KB Time limit exceeded
46 Execution timed out 1081 ms 56164 KB Time limit exceeded
47 Execution timed out 1075 ms 56316 KB Time limit exceeded
48 Execution timed out 1084 ms 56340 KB Time limit exceeded
49 Execution timed out 1090 ms 56204 KB Time limit exceeded
50 Execution timed out 1068 ms 56200 KB Time limit exceeded
51 Execution timed out 1077 ms 56284 KB Time limit exceeded
52 Execution timed out 1048 ms 56228 KB Time limit exceeded
53 Execution timed out 1079 ms 56232 KB Time limit exceeded
54 Execution timed out 1084 ms 56212 KB Time limit exceeded
55 Execution timed out 1081 ms 56272 KB Time limit exceeded
56 Correct 911 ms 56228 KB Output is correct
57 Execution timed out 1083 ms 56168 KB Time limit exceeded
58 Execution timed out 1068 ms 56216 KB Time limit exceeded
59 Execution timed out 1043 ms 56176 KB Time limit exceeded
60 Execution timed out 1056 ms 56288 KB Time limit exceeded
61 Execution timed out 1089 ms 56256 KB Time limit exceeded
62 Execution timed out 1078 ms 56260 KB Time limit exceeded
63 Correct 926 ms 56352 KB Output is correct
64 Execution timed out 1076 ms 56176 KB Time limit exceeded
65 Execution timed out 1088 ms 56284 KB Time limit exceeded
66 Execution timed out 1082 ms 56308 KB Time limit exceeded
67 Execution timed out 1081 ms 56364 KB Time limit exceeded
68 Execution timed out 1079 ms 56204 KB Time limit exceeded
69 Execution timed out 1089 ms 56140 KB Time limit exceeded
70 Execution timed out 1014 ms 36236 KB Time limit exceeded
71 Execution timed out 1081 ms 56216 KB Time limit exceeded
72 Execution timed out 1077 ms 56224 KB Time limit exceeded
73 Execution timed out 1077 ms 56172 KB Time limit exceeded
74 Execution timed out 1088 ms 56244 KB Time limit exceeded
75 Execution timed out 1083 ms 56184 KB Time limit exceeded
76 Execution timed out 1086 ms 56136 KB Time limit exceeded
77 Execution timed out 1079 ms 56172 KB Time limit exceeded
78 Execution timed out 1088 ms 56168 KB Time limit exceeded
79 Execution timed out 1082 ms 56236 KB Time limit exceeded
80 Execution timed out 1088 ms 56272 KB Time limit exceeded
81 Execution timed out 1084 ms 56172 KB Time limit exceeded
82 Execution timed out 1076 ms 56320 KB Time limit exceeded
83 Execution timed out 1079 ms 56180 KB Time limit exceeded
84 Execution timed out 1078 ms 56208 KB Time limit exceeded
85 Execution timed out 1058 ms 56160 KB Time limit exceeded
86 Execution timed out 1085 ms 56276 KB Time limit exceeded
87 Execution timed out 1073 ms 56176 KB Time limit exceeded
88 Execution timed out 1072 ms 56216 KB Time limit exceeded
89 Execution timed out 1075 ms 56348 KB Time limit exceeded
90 Incorrect 965 ms 36192 KB Output isn't correct
91 Execution timed out 1084 ms 56164 KB Time limit exceeded
92 Execution timed out 1080 ms 56208 KB Time limit exceeded
93 Execution timed out 1081 ms 56464 KB Time limit exceeded
94 Execution timed out 1072 ms 56196 KB Time limit exceeded
95 Execution timed out 1067 ms 56172 KB Time limit exceeded
96 Execution timed out 1059 ms 56200 KB Time limit exceeded
97 Execution timed out 1068 ms 56352 KB Time limit exceeded
98 Execution timed out 1076 ms 56316 KB Time limit exceeded
99 Execution timed out 1074 ms 56332 KB Time limit exceeded
100 Execution timed out 1060 ms 56384 KB Time limit exceeded