Submission #705999

# Submission time Handle Problem Language Result Execution time Memory
705999 2023-03-05T18:19:49 Z KiriLL1ca Bomb (IZhO17_bomb) C++17
30 / 100
1000 ms 58336 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;
typedef pair <ll, ll> pll;

const int N = 2505;

string a[N];
int p[N][N];

inline int 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;
}

inline bool bad (int s, int t, int n, int m) {
    vector <vector <int>> f (n + 1, vector <int> (m + 1));

    for (int i = 0; i + s - 1 < n; ++i) {
        for (int j = 0; j + t - 1 < m; ++j) {
            if (get(i, j, i + s - 1, j + t - 1) == s * t) {
                ++f[i][j];
                --f[i + s][j];
                --f[i][j + t];
                ++f[i + s][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;
}


inline void solve () {
    int n, m; cin >> n >> m;
    for (int i = 0; i < n; ++i) cin >> a[i];

    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');
        }
    }

    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        int res = 0;
        for (int j = 9; ~j; --j) {
            res += pw(j);
            if (res > m || bad(i, res, n, m)) res -= pw(j);
        }
        umax(ans, i * res);
    }
    cout << ans << endl;
}

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 340 KB Output is correct
2 Correct 1 ms 412 KB Output is correct
3 Correct 313 ms 10644 KB Output is correct
4 Correct 302 ms 10580 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 408 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 388 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 14 ms 664 KB Output is correct
18 Correct 13 ms 740 KB Output is correct
19 Correct 33 ms 852 KB Output is correct
20 Correct 34 ms 844 KB Output is correct
21 Correct 12 ms 676 KB Output is correct
22 Correct 25 ms 724 KB Output is correct
23 Correct 47 ms 852 KB Output is correct
24 Correct 24 ms 796 KB Output is correct
25 Correct 48 ms 852 KB Output is correct
26 Correct 52 ms 852 KB Output is correct
27 Execution timed out 1084 ms 2524 KB Time limit exceeded
28 Execution timed out 1073 ms 2808 KB Time limit exceeded
29 Execution timed out 1079 ms 3308 KB Time limit exceeded
30 Execution timed out 1086 ms 4228 KB Time limit exceeded
31 Execution timed out 1084 ms 3504 KB Time limit exceeded
32 Execution timed out 1078 ms 3596 KB Time limit exceeded
33 Execution timed out 1071 ms 4360 KB Time limit exceeded
34 Execution timed out 1063 ms 2660 KB Time limit exceeded
35 Execution timed out 1085 ms 4392 KB Time limit exceeded
36 Execution timed out 1063 ms 4360 KB Time limit exceeded
37 Correct 1 ms 468 KB Output is correct
38 Execution timed out 1016 ms 57892 KB Time limit exceeded
39 Correct 1 ms 468 KB Output is correct
40 Execution timed out 1075 ms 11788 KB Time limit exceeded
41 Correct 1 ms 468 KB Output is correct
42 Correct 49 ms 852 KB Output is correct
43 Execution timed out 1012 ms 57856 KB Time limit exceeded
44 Execution timed out 1061 ms 4356 KB Time limit exceeded
45 Execution timed out 1080 ms 57900 KB Time limit exceeded
46 Execution timed out 1008 ms 57740 KB Time limit exceeded
47 Execution timed out 1073 ms 57748 KB Time limit exceeded
48 Execution timed out 1060 ms 57796 KB Time limit exceeded
49 Execution timed out 1022 ms 57744 KB Time limit exceeded
50 Execution timed out 1025 ms 57736 KB Time limit exceeded
51 Execution timed out 1078 ms 57668 KB Time limit exceeded
52 Execution timed out 1093 ms 57536 KB Time limit exceeded
53 Execution timed out 1031 ms 57516 KB Time limit exceeded
54 Execution timed out 1077 ms 57536 KB Time limit exceeded
55 Execution timed out 1092 ms 57512 KB Time limit exceeded
56 Execution timed out 1025 ms 57528 KB Time limit exceeded
57 Execution timed out 1044 ms 57460 KB Time limit exceeded
58 Execution timed out 1054 ms 57564 KB Time limit exceeded
59 Execution timed out 1027 ms 57400 KB Time limit exceeded
60 Execution timed out 1095 ms 57476 KB Time limit exceeded
61 Execution timed out 1095 ms 57484 KB Time limit exceeded
62 Execution timed out 1028 ms 57480 KB Time limit exceeded
63 Execution timed out 1066 ms 57724 KB Time limit exceeded
64 Execution timed out 1034 ms 57488 KB Time limit exceeded
65 Execution timed out 1025 ms 57488 KB Time limit exceeded
66 Execution timed out 1100 ms 57528 KB Time limit exceeded
67 Execution timed out 1032 ms 57848 KB Time limit exceeded
68 Execution timed out 1006 ms 58232 KB Time limit exceeded
69 Execution timed out 1035 ms 58108 KB Time limit exceeded
70 Execution timed out 1014 ms 41068 KB Time limit exceeded
71 Execution timed out 1026 ms 58280 KB Time limit exceeded
72 Execution timed out 1010 ms 58164 KB Time limit exceeded
73 Execution timed out 1054 ms 58120 KB Time limit exceeded
74 Execution timed out 1101 ms 57952 KB Time limit exceeded
75 Execution timed out 1038 ms 57988 KB Time limit exceeded
76 Execution timed out 1074 ms 57528 KB Time limit exceeded
77 Execution timed out 1077 ms 57692 KB Time limit exceeded
78 Execution timed out 1053 ms 57656 KB Time limit exceeded
79 Execution timed out 1062 ms 57684 KB Time limit exceeded
80 Execution timed out 1077 ms 57784 KB Time limit exceeded
81 Execution timed out 1020 ms 57696 KB Time limit exceeded
82 Execution timed out 1032 ms 57692 KB Time limit exceeded
83 Execution timed out 1027 ms 57652 KB Time limit exceeded
84 Execution timed out 1029 ms 57764 KB Time limit exceeded
85 Execution timed out 1048 ms 57844 KB Time limit exceeded
86 Execution timed out 1042 ms 57772 KB Time limit exceeded
87 Execution timed out 1027 ms 57704 KB Time limit exceeded
88 Execution timed out 1094 ms 57664 KB Time limit exceeded
89 Execution timed out 1051 ms 57796 KB Time limit exceeded
90 Execution timed out 1061 ms 41524 KB Time limit exceeded
91 Execution timed out 1031 ms 57696 KB Time limit exceeded
92 Execution timed out 1042 ms 57752 KB Time limit exceeded
93 Execution timed out 1014 ms 57720 KB Time limit exceeded
94 Execution timed out 1066 ms 57972 KB Time limit exceeded
95 Execution timed out 1041 ms 58152 KB Time limit exceeded
96 Execution timed out 1074 ms 58336 KB Time limit exceeded
97 Execution timed out 1064 ms 57912 KB Time limit exceeded
98 Execution timed out 1014 ms 57948 KB Time limit exceeded
99 Execution timed out 1018 ms 57920 KB Time limit exceeded
100 Execution timed out 1032 ms 57912 KB Time limit exceeded