# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1030394 |
2024-07-22T04:33:23 Z |
caterpillow |
Bomb (IZhO17_bomb) |
C++17 |
|
1000 ms |
57116 KB |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using ll = long long;
#define vt vector
#define f first
#define s second
#define all(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, b) FOR(i, 0, b)
#define ROF(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define pb push_back
#define endl '\n'
#ifndef LOCAL
#define cerr if (0) std::cerr
#endif
/*
N^3: find max width for each given height
*/
int rs, cs;
vt<vt<bool>> grid;
vt<vt<int>> sfx;
int sum(int r1, int c1, int r2, int c2) {
r2 = min(r2, rs - 1);
c2 = min(c2, cs - 1);
return sfx[r1][c1] - sfx[r1][c2 + 1] - sfx[r2 + 1][c1] + sfx[r2 + 1][c2 + 1];
}
bool check(int w, int h) {
vt<vt<int>> pfx(rs, vt<int>(cs));
auto is_covered = [&] (int r, int c) {
return (pfx[r][c] - (r - h >= 0 ? pfx[r - h][c] : 0) - (c - w >= 0 ? pfx[r][c - w] : 0) + (r - h >= 0 && c - w >= 0 ? pfx[r - h][c - w] : 0)) > 0;
};
auto add = [&] (int r, int c) {
pfx[r][c] += (r ? pfx[r - 1][c] : 0) + (c ? pfx[r][c - 1] : 0) - (r && c ? pfx[r - 1][c - 1] : 0);
};
F0R (r, rs - 1) {
F0R (c, cs - 1) {
if (sum(r, c, r + h - 1, c + w - 1) == w * h) {
pfx[r][c]++;
}
add(r, c);
if (grid[r][c] == 1) {
if (!is_covered(r, c)) return false;
}
}
}
return true;
}
int ans = 0;
void solve(int mnh, int mxh, int mnw, int mxw) {
if (mxh < mnh || mxw < mnw) return;
if (mxh * mxw <= ans) return;
int h = (mnh + mxh) / 2;
int lo = mnw - 1, hi = mxw + 1;
while (hi - lo > 1) {
int w = (lo + hi) / 2;
if (check(w, h)) lo = w;
else hi = w;
}
ans = max(ans, h * lo);
solve(mnh, h - 1, lo, mxw);
solve(h + 1, mxh, mnw, lo);
}
main() {
cin.tie(0)->sync_with_stdio();
cin >> rs >> cs;
rs += 2, cs += 2;
grid.resize(rs, vt<bool>(cs));
sfx.resize(rs + 1, vt<int>(cs + 1));
FOR (r, 1, rs - 1) {
FOR (c, 1, cs - 1) {
char ch; cin >> ch;
grid[r][c] = sfx[r][c] = ch - '0';
}
}
ROF (r, 0, rs) ROF (c, 0, cs) sfx[r][c] += sfx[r][c + 1];
ROF (r, 0, rs) ROF (c, 0, cs) sfx[r][c] += sfx[r + 1][c];
int mxw = cs, mxh = rs;
F0R (r, rs) {
int streak = 0;
F0R (c, cs) {
if (grid[r][c]) streak++;
else if (streak) mxw = min(mxw, streak), streak = 0;
}
}
F0R (c, cs) {
int streak = 0;
F0R (r, rs) {
if (grid[r][c]) streak++;
else if (streak) mxh = min(mxh, streak), streak = 0;
}
}
solve(1, mxh, 1, mxw);
cout << ans << endl;
}
Compilation message
bomb.cpp:80:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
80 | main() {
| ^~~~
bomb.cpp: In function 'int main()':
bomb.cpp:90:36: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
90 | grid[r][c] = sfx[r][c] = ch - '0';
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
860 KB |
Output is correct |
4 |
Correct |
1 ms |
860 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 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 |
408 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
444 KB |
Output is correct |
18 |
Correct |
0 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 |
352 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
352 KB |
Output is correct |
24 |
Correct |
1 ms |
420 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
3 ms |
1180 KB |
Output is correct |
28 |
Correct |
7 ms |
1440 KB |
Output is correct |
29 |
Correct |
41 ms |
1624 KB |
Output is correct |
30 |
Correct |
40 ms |
2168 KB |
Output is correct |
31 |
Correct |
24 ms |
1820 KB |
Output is correct |
32 |
Correct |
22 ms |
2028 KB |
Output is correct |
33 |
Correct |
54 ms |
2324 KB |
Output is correct |
34 |
Correct |
7 ms |
1444 KB |
Output is correct |
35 |
Correct |
26 ms |
2688 KB |
Output is correct |
36 |
Correct |
37 ms |
2384 KB |
Output is correct |
37 |
Correct |
1 ms |
344 KB |
Output is correct |
38 |
Execution timed out |
1098 ms |
56728 KB |
Time limit exceeded |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
229 ms |
7516 KB |
Output is correct |
41 |
Correct |
1 ms |
344 KB |
Output is correct |
42 |
Correct |
2 ms |
348 KB |
Output is correct |
43 |
Execution timed out |
1051 ms |
56696 KB |
Time limit exceeded |
44 |
Correct |
78 ms |
2316 KB |
Output is correct |
45 |
Execution timed out |
1082 ms |
56784 KB |
Time limit exceeded |
46 |
Correct |
929 ms |
56696 KB |
Output is correct |
47 |
Execution timed out |
1072 ms |
56960 KB |
Time limit exceeded |
48 |
Execution timed out |
1039 ms |
56736 KB |
Time limit exceeded |
49 |
Correct |
468 ms |
56696 KB |
Output is correct |
50 |
Execution timed out |
1070 ms |
56704 KB |
Time limit exceeded |
51 |
Execution timed out |
1088 ms |
56768 KB |
Time limit exceeded |
52 |
Execution timed out |
1048 ms |
56764 KB |
Time limit exceeded |
53 |
Execution timed out |
1055 ms |
56764 KB |
Time limit exceeded |
54 |
Execution timed out |
1033 ms |
56936 KB |
Time limit exceeded |
55 |
Execution timed out |
1035 ms |
56876 KB |
Time limit exceeded |
56 |
Execution timed out |
1079 ms |
56792 KB |
Time limit exceeded |
57 |
Execution timed out |
1042 ms |
56696 KB |
Time limit exceeded |
58 |
Execution timed out |
1065 ms |
56740 KB |
Time limit exceeded |
59 |
Execution timed out |
1066 ms |
56732 KB |
Time limit exceeded |
60 |
Correct |
895 ms |
56700 KB |
Output is correct |
61 |
Execution timed out |
1014 ms |
56696 KB |
Time limit exceeded |
62 |
Execution timed out |
1067 ms |
56700 KB |
Time limit exceeded |
63 |
Execution timed out |
1074 ms |
56868 KB |
Time limit exceeded |
64 |
Execution timed out |
1082 ms |
56704 KB |
Time limit exceeded |
65 |
Execution timed out |
1101 ms |
56908 KB |
Time limit exceeded |
66 |
Execution timed out |
1077 ms |
56700 KB |
Time limit exceeded |
67 |
Execution timed out |
1051 ms |
56732 KB |
Time limit exceeded |
68 |
Execution timed out |
1079 ms |
56700 KB |
Time limit exceeded |
69 |
Execution timed out |
1046 ms |
56716 KB |
Time limit exceeded |
70 |
Execution timed out |
1042 ms |
36592 KB |
Time limit exceeded |
71 |
Execution timed out |
1050 ms |
57116 KB |
Time limit exceeded |
72 |
Execution timed out |
1047 ms |
56800 KB |
Time limit exceeded |
73 |
Execution timed out |
1067 ms |
56724 KB |
Time limit exceeded |
74 |
Execution timed out |
1010 ms |
56768 KB |
Time limit exceeded |
75 |
Execution timed out |
1081 ms |
56816 KB |
Time limit exceeded |
76 |
Execution timed out |
1018 ms |
56784 KB |
Time limit exceeded |
77 |
Execution timed out |
1094 ms |
56772 KB |
Time limit exceeded |
78 |
Execution timed out |
1039 ms |
56756 KB |
Time limit exceeded |
79 |
Execution timed out |
1012 ms |
56744 KB |
Time limit exceeded |
80 |
Correct |
771 ms |
56732 KB |
Output is correct |
81 |
Execution timed out |
1073 ms |
56920 KB |
Time limit exceeded |
82 |
Execution timed out |
1041 ms |
56772 KB |
Time limit exceeded |
83 |
Execution timed out |
1062 ms |
56972 KB |
Time limit exceeded |
84 |
Correct |
895 ms |
56704 KB |
Output is correct |
85 |
Execution timed out |
1033 ms |
56776 KB |
Time limit exceeded |
86 |
Correct |
558 ms |
56768 KB |
Output is correct |
87 |
Execution timed out |
1036 ms |
56888 KB |
Time limit exceeded |
88 |
Execution timed out |
1030 ms |
57016 KB |
Time limit exceeded |
89 |
Execution timed out |
1099 ms |
56780 KB |
Time limit exceeded |
90 |
Execution timed out |
1061 ms |
36572 KB |
Time limit exceeded |
91 |
Execution timed out |
1069 ms |
56664 KB |
Time limit exceeded |
92 |
Execution timed out |
1051 ms |
56872 KB |
Time limit exceeded |
93 |
Correct |
685 ms |
56800 KB |
Output is correct |
94 |
Execution timed out |
1066 ms |
56996 KB |
Time limit exceeded |
95 |
Execution timed out |
1067 ms |
56740 KB |
Time limit exceeded |
96 |
Execution timed out |
1025 ms |
56708 KB |
Time limit exceeded |
97 |
Correct |
596 ms |
56796 KB |
Output is correct |
98 |
Execution timed out |
1037 ms |
57052 KB |
Time limit exceeded |
99 |
Execution timed out |
1078 ms |
56788 KB |
Time limit exceeded |
100 |
Correct |
791 ms |
56752 KB |
Output is correct |