# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
945074 |
2024-03-13T11:26:46 Z |
atom |
Bomb (IZhO17_bomb) |
C++17 |
|
1000 ms |
131072 KB |
#include "bits/stdc++.h"
// @JASPER'S BOILERPLATE
using namespace std;
using ll = long long;
#ifdef JASPER
#include "debug.h"
#else
#define debug(...) 166
#endif
signed main() {
cin.tie(0) -> sync_with_stdio(0);
#ifdef JASPER
freopen("in1", "r", stdin);
#endif
int n, m;
cin >> n >> m;
vector <vector <int>> a(n + 5, vector <int> (m + 5, 0));
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
char x; cin >> x;
a[i][j] = x - '0';
}
}
// for (int i = 1; i <= n; ++i)
// for (int j = 1; j <= m; ++j)
// cout << a[i][j] << " \n"[j == m];
//sub1: shortest consecutive 1ss
if (n == 1 || m == 1) {
if (n == 1) {
int ans = 1e9;
for (int i = 1; i <= m; ++i) {
if (a[1][i] == 0) continue;
int cur = 0;
while (i <= m && a[1][i]) {
++cur;
++i;
}
ans = min(ans, cur);
}
cout << ans << "\n";
return 0;
}
if (m == 1) {
int ans = 1e9;
for (int i = 1; i <= n; ++i) {
if (a[i][1] == 0) continue;
int cur = 0;
while (i <= n && a[i][1]) {
++cur;
++i;
}
ans = min(ans, cur);
}
cout << ans << "\n";
return 0;
}
}
// sub3
// if (n <= 450 && m <= 450) {
// vector <vector <int>> prf(n + 5, vector <int> (m + 5, 0));
// int earth = 0;
// for (int i = 1; i <= n; ++i) {
// for (int j = 1; j <= m; ++j) {
// earth += (a[i][j] == 0);
// prf[i][j] = prf[i][j - 1] + prf[i - 1][j] - prf[i - 1][j - 1] + a[i][j];
// }
// }
// int ans = 0;
// for (int x = 1; x <= n; ++x) {
// for (int y = 1; y <= m; ++y) {
// if (x * y <= ans) continue;
// // prf(l)++, prf(r + 1)--;
// vector <vector <int>> dmg(n + 2, vector <int> (m + 2, 0));
// for (int i = 1; i + x - 1 <= n; ++i) {
// for (int j = 1; j + y - 1 <= m; ++j) {
// int I = i + x - 1, J = j + y - 1;
// if (prf[I][J] + prf[i - 1][j - 1] - prf[I][j - 1] - prf[i - 1][J] == x * y) {
// dmg[i][j] += 1;
// dmg[I + 1][j] -= 1;
// dmg[i][J + 1] -= 1;
// dmg[I + 1][J + 1] += 1;
// }
// }
// }
// for (int i = 1; i <= n; ++i)
// for (int j = 1; j <= m; ++j)
// dmg[i][j] += dmg[i - 1][j] + dmg[i][j - 1] - dmg[i - 1][j - 1];
// bool valid = 1;
// for (int i = 1; i <= n; ++i) {
// for (int j = 1; j <= m; ++j) {
// if (a[i][j] && !dmg[i][j])
// valid = 0;
// }
// }
// if (valid) ans = max(ans, x * y);
// }
// }
// cout << ans << "\n";
// return 0;
// }
// two pointer to optimize
vector <vector <int>> lt(n + 5, vector <int> (m + 5, 0)), rt(n + 5, vector <int> (m + 5, 0));
vector <int> w(n + 5, 1e9); // ans(i) : W when H = i
int min_h = 1e9;// minimum vertical strip of 1s;
for (int _i = 0; _i <= 1; _i++) {
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j)
a[i][j]? lt[i][j] = (lt[i][j - 1] + 1) : 0;
for (int j = m; j >= 1; --j)
a[i][j]? rt[i][j] = (rt[i][j + 1] + 1) : 0;
for (int j = 1; j <= m; ++j)
if (a[i][j]) w[1] = min(w[1], rt[i][j] + lt[i][j] - (lt[i][j] && rt[i][j]));
}
// find feasible height
for (int j = 1; j <= m; ++j) {
int k = 0; // length of consecutive 1s of current column
int l = 1e9, r = 1e9;
for (int i = 1; i <= n; ++i) {
if (a[i][j]) {
++k;
l = min(l, lt[i][j]);
r = min(r, rt[i][j]);
w[k] = min(w[k], r + l - (lt[i][j] && rt[i][j]));
}
else {
if (k) min_h = min(min_h, k);
l = r = 1e9;
k = 0;
}
}
}
for (int i = 1; i <= n / 2; ++i) {
for (int j = 1; j <= m; ++j)
swap(a[i][j], a[n - i + 1][j]);
}
}
int ans = 0;
for (int h = 1; h <= min_h; ++h) {
w[h + 1] = min(w[h + 1], w[h]); // width is bounded by the minimum horizontal strip
ans = max(ans, w[h] * h);
}
cout << ans << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 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 |
348 KB |
Output is correct |
9 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
3 ms |
1372 KB |
Output is correct |
28 |
Correct |
3 ms |
1628 KB |
Output is correct |
29 |
Correct |
5 ms |
1880 KB |
Output is correct |
30 |
Incorrect |
6 ms |
2764 KB |
Output isn't correct |
31 |
Incorrect |
4 ms |
2136 KB |
Output isn't correct |
32 |
Incorrect |
4 ms |
2140 KB |
Output isn't correct |
33 |
Correct |
6 ms |
2908 KB |
Output is correct |
34 |
Correct |
2 ms |
1372 KB |
Output is correct |
35 |
Correct |
5 ms |
2908 KB |
Output is correct |
36 |
Correct |
8 ms |
2952 KB |
Output is correct |
37 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
38 |
Execution timed out |
2714 ms |
131072 KB |
Time limit exceeded |
39 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
40 |
Correct |
36 ms |
9716 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
1 ms |
348 KB |
Output is correct |
43 |
Correct |
405 ms |
74380 KB |
Output is correct |
44 |
Correct |
7 ms |
2908 KB |
Output is correct |
45 |
Incorrect |
398 ms |
74388 KB |
Output isn't correct |
46 |
Correct |
362 ms |
74380 KB |
Output is correct |
47 |
Incorrect |
413 ms |
74324 KB |
Output isn't correct |
48 |
Correct |
389 ms |
74388 KB |
Output is correct |
49 |
Correct |
502 ms |
74496 KB |
Output is correct |
50 |
Correct |
378 ms |
74252 KB |
Output is correct |
51 |
Correct |
388 ms |
74388 KB |
Output is correct |
52 |
Correct |
371 ms |
74240 KB |
Output is correct |
53 |
Correct |
373 ms |
74496 KB |
Output is correct |
54 |
Correct |
293 ms |
74320 KB |
Output is correct |
55 |
Correct |
292 ms |
74580 KB |
Output is correct |
56 |
Execution timed out |
2667 ms |
131072 KB |
Time limit exceeded |
57 |
Correct |
288 ms |
74384 KB |
Output is correct |
58 |
Correct |
289 ms |
74324 KB |
Output is correct |
59 |
Correct |
297 ms |
74508 KB |
Output is correct |
60 |
Correct |
360 ms |
74316 KB |
Output is correct |
61 |
Correct |
500 ms |
74384 KB |
Output is correct |
62 |
Correct |
508 ms |
74324 KB |
Output is correct |
63 |
Correct |
499 ms |
74576 KB |
Output is correct |
64 |
Correct |
300 ms |
74516 KB |
Output is correct |
65 |
Correct |
362 ms |
74320 KB |
Output is correct |
66 |
Correct |
374 ms |
74576 KB |
Output is correct |
67 |
Correct |
385 ms |
74236 KB |
Output is correct |
68 |
Correct |
413 ms |
74380 KB |
Output is correct |
69 |
Correct |
275 ms |
74392 KB |
Output is correct |
70 |
Correct |
131 ms |
47700 KB |
Output is correct |
71 |
Incorrect |
265 ms |
74380 KB |
Output isn't correct |
72 |
Correct |
277 ms |
74320 KB |
Output is correct |
73 |
Incorrect |
295 ms |
74492 KB |
Output isn't correct |
74 |
Incorrect |
278 ms |
74244 KB |
Output isn't correct |
75 |
Incorrect |
298 ms |
74324 KB |
Output isn't correct |
76 |
Correct |
294 ms |
74324 KB |
Output is correct |
77 |
Correct |
294 ms |
74324 KB |
Output is correct |
78 |
Correct |
301 ms |
74472 KB |
Output is correct |
79 |
Correct |
190 ms |
74384 KB |
Output is correct |
80 |
Correct |
205 ms |
74384 KB |
Output is correct |
81 |
Correct |
208 ms |
74320 KB |
Output is correct |
82 |
Correct |
297 ms |
74320 KB |
Output is correct |
83 |
Incorrect |
299 ms |
74384 KB |
Output isn't correct |
84 |
Correct |
192 ms |
74240 KB |
Output is correct |
85 |
Correct |
290 ms |
74388 KB |
Output is correct |
86 |
Correct |
462 ms |
74388 KB |
Output is correct |
87 |
Correct |
289 ms |
74576 KB |
Output is correct |
88 |
Incorrect |
299 ms |
74236 KB |
Output isn't correct |
89 |
Correct |
344 ms |
74580 KB |
Output is correct |
90 |
Incorrect |
174 ms |
47700 KB |
Output isn't correct |
91 |
Correct |
346 ms |
74320 KB |
Output is correct |
92 |
Correct |
345 ms |
74392 KB |
Output is correct |
93 |
Correct |
447 ms |
74324 KB |
Output is correct |
94 |
Correct |
348 ms |
74324 KB |
Output is correct |
95 |
Incorrect |
307 ms |
74320 KB |
Output isn't correct |
96 |
Incorrect |
307 ms |
74580 KB |
Output isn't correct |
97 |
Correct |
484 ms |
74388 KB |
Output is correct |
98 |
Correct |
324 ms |
74236 KB |
Output is correct |
99 |
Correct |
374 ms |
74380 KB |
Output is correct |
100 |
Correct |
455 ms |
74324 KB |
Output is correct |