Submission #682565

# Submission time Handle Problem Language Result Execution time Memory
682565 2023-01-16T14:11:34 Z opPO Bomb (IZhO17_bomb) C++17
41 / 100
1000 ms 79792 KB
#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>

using namespace std;

#define f first
#define s second
#define pb push_back
#define ld long double
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define vec vector

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());
const ld eps = 1e-6;
const int mod = 998244353;
const int oo = 2e9;
const ll OO = 2e18;
const int N = 2501;
int n, m, a[N][N], pref[N][N], p[N][N];

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

bool check(int h, int w)
{
    for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) p[i][j] = 0;
    for (int x1 = 1; x1 <= n; x1++)
    {
        for (int y1 = 1; y1 <= m; y1++)
        {
            int x2 = x1 + h - 1, y2 = y1 + w - 1;
            if (x2 > n || y2 > m) break;
            if (get(x1, y1, x2, y2) == h * w)
            {
                p[x1][y1]++;
                p[x1][y2 + 1]--;
                p[x2 + 1][y1]--;
                p[x2 + 1][y2 + 1]++;
            }
        }
    }
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            p[i][j] += p[i - 1][j];
            p[i][j] += p[i][j - 1];
            p[i][j] -= p[i - 1][j - 1];
            if (a[i][j] == 1 && p[i][j] == 0) return false;
        }
    }
    return true;
}

void solve()
{
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            char c;
            cin >> c;
            a[i][j] = c - '0';
            pref[i][j] += a[i][j];
            pref[i][j] += pref[i - 1][j];
            pref[i][j] += pref[i][j - 1];
            pref[i][j] -= pref[i - 1][j - 1];
        }
    }
    int ans = 0;
    for (int h = 1; h <= n; h++)
    {
        int l = 0, r = m;
        while (l < r)
        {
            int mid = (l + r + 1) / 2;
            if (check(h, mid)) l = mid;
            else r = mid - 1;
        }
        ans = max(ans, h * l);
    }
    cout << ans;
}

int32_t main()
{
//    freopen("bomb.in", "r", stdin);
//    freopen("bomb.out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 133 ms 30460 KB Output is correct
4 Correct 121 ms 30460 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 464 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 588 KB Output is correct
17 Correct 2 ms 1108 KB Output is correct
18 Correct 2 ms 1236 KB Output is correct
19 Correct 4 ms 1492 KB Output is correct
20 Correct 5 ms 1552 KB Output is correct
21 Correct 2 ms 980 KB Output is correct
22 Correct 5 ms 1232 KB Output is correct
23 Correct 6 ms 1620 KB Output is correct
24 Correct 3 ms 1364 KB Output is correct
25 Correct 7 ms 1684 KB Output is correct
26 Correct 7 ms 1620 KB Output is correct
27 Correct 145 ms 4824 KB Output is correct
28 Correct 164 ms 5232 KB Output is correct
29 Correct 346 ms 6608 KB Output is correct
30 Correct 671 ms 7904 KB Output is correct
31 Correct 296 ms 6228 KB Output is correct
32 Correct 419 ms 7192 KB Output is correct
33 Correct 751 ms 8312 KB Output is correct
34 Correct 164 ms 5600 KB Output is correct
35 Correct 542 ms 8320 KB Output is correct
36 Correct 758 ms 8320 KB Output is correct
37 Correct 1 ms 468 KB Output is correct
38 Execution timed out 1068 ms 79620 KB Time limit exceeded
39 Correct 1 ms 468 KB Output is correct
40 Execution timed out 1086 ms 20556 KB Time limit exceeded
41 Correct 1 ms 588 KB Output is correct
42 Correct 10 ms 1684 KB Output is correct
43 Execution timed out 1087 ms 79648 KB Time limit exceeded
44 Correct 765 ms 8316 KB Output is correct
45 Execution timed out 1080 ms 79564 KB Time limit exceeded
46 Execution timed out 1082 ms 79564 KB Time limit exceeded
47 Execution timed out 1086 ms 79692 KB Time limit exceeded
48 Execution timed out 1077 ms 79604 KB Time limit exceeded
49 Execution timed out 1084 ms 79552 KB Time limit exceeded
50 Execution timed out 1072 ms 79540 KB Time limit exceeded
51 Execution timed out 1079 ms 79616 KB Time limit exceeded
52 Execution timed out 1080 ms 79568 KB Time limit exceeded
53 Execution timed out 1080 ms 79564 KB Time limit exceeded
54 Execution timed out 1084 ms 79608 KB Time limit exceeded
55 Execution timed out 1107 ms 79736 KB Time limit exceeded
56 Execution timed out 1071 ms 79676 KB Time limit exceeded
57 Execution timed out 1051 ms 79620 KB Time limit exceeded
58 Execution timed out 1068 ms 79624 KB Time limit exceeded
59 Execution timed out 1070 ms 79568 KB Time limit exceeded
60 Execution timed out 1069 ms 79524 KB Time limit exceeded
61 Execution timed out 1082 ms 79620 KB Time limit exceeded
62 Execution timed out 1085 ms 79636 KB Time limit exceeded
63 Execution timed out 1070 ms 79564 KB Time limit exceeded
64 Execution timed out 1071 ms 79556 KB Time limit exceeded
65 Execution timed out 1077 ms 79692 KB Time limit exceeded
66 Execution timed out 1059 ms 79576 KB Time limit exceeded
67 Execution timed out 1062 ms 79568 KB Time limit exceeded
68 Execution timed out 1026 ms 79676 KB Time limit exceeded
69 Execution timed out 1078 ms 79792 KB Time limit exceeded
70 Execution timed out 1089 ms 62932 KB Time limit exceeded
71 Execution timed out 1078 ms 79552 KB Time limit exceeded
72 Execution timed out 1080 ms 79632 KB Time limit exceeded
73 Execution timed out 1057 ms 79632 KB Time limit exceeded
74 Execution timed out 1071 ms 79560 KB Time limit exceeded
75 Execution timed out 1074 ms 79608 KB Time limit exceeded
76 Execution timed out 1064 ms 79600 KB Time limit exceeded
77 Execution timed out 1061 ms 79588 KB Time limit exceeded
78 Execution timed out 1080 ms 79632 KB Time limit exceeded
79 Execution timed out 1067 ms 79620 KB Time limit exceeded
80 Execution timed out 1082 ms 79552 KB Time limit exceeded
81 Execution timed out 1076 ms 79624 KB Time limit exceeded
82 Execution timed out 1074 ms 79572 KB Time limit exceeded
83 Execution timed out 1071 ms 79600 KB Time limit exceeded
84 Execution timed out 1051 ms 79692 KB Time limit exceeded
85 Execution timed out 1067 ms 79564 KB Time limit exceeded
86 Execution timed out 1085 ms 79628 KB Time limit exceeded
87 Execution timed out 1078 ms 79616 KB Time limit exceeded
88 Execution timed out 1057 ms 79624 KB Time limit exceeded
89 Execution timed out 1078 ms 79572 KB Time limit exceeded
90 Execution timed out 1092 ms 62940 KB Time limit exceeded
91 Execution timed out 1088 ms 79692 KB Time limit exceeded
92 Execution timed out 1084 ms 79652 KB Time limit exceeded
93 Execution timed out 1084 ms 79584 KB Time limit exceeded
94 Execution timed out 1087 ms 79636 KB Time limit exceeded
95 Execution timed out 1077 ms 79640 KB Time limit exceeded
96 Execution timed out 1014 ms 79716 KB Time limit exceeded
97 Execution timed out 1092 ms 79568 KB Time limit exceeded
98 Execution timed out 1088 ms 79568 KB Time limit exceeded
99 Execution timed out 1070 ms 79564 KB Time limit exceeded
100 Execution timed out 1075 ms 79592 KB Time limit exceeded