Submission #711555

# Submission time Handle Problem Language Result Execution time Memory
711555 2023-03-17T08:36:55 Z pavement Bomb (IZhO17_bomb) C++17
100 / 100
215 ms 104748 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define g0(a) get<0>(a)
#define g1(a) get<1>(a)
#define g2(a) get<2>(a)
#define g3(a) get<3>(a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
using db = double;
using ll = long long;
using ld = long double;
using ii = pair<int, int>;
using iii = tuple<int, int, int>;
using iiii = tuple<int, int, int, int>;
template<class key, class value = null_type, class cmp = less<key> >
using ordered_set = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

int N, M, ans[2505], top[2505][2505], down[2505][2505];
char A[2505][2505];

main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> N >> M;
	for (int i = 1; i <= M; i++) {
		ans[i] = (int)1e16;
	}
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= M; j++) {
			cin >> A[i][j];
		}
	}
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= M; j++) {
			if (A[i][j] == '1') {
				top[i][j] = (top[i - 1][j] ? top[i - 1][j] : i);
			}
		}
	}
	for (int i = N; i >= 1; i--) {
		for (int j = 1; j <= M; j++) {
			if (A[i][j] == '1') {
				down[i][j] = (down[i + 1][j] ? down[i + 1][j] : i);
				ans[1] = min(ans[1], down[i][j] - top[i][j] + 1);
			}
		}
	}
	for (int iter = 0; iter < 2; iter++) {
		for (int i = 1; i <= N; i++) {
			for (int l = 1, r = 1; l <= M; ) {
				while (r <= M && A[i][r] == '1') r++;
				if (l == r) {
					l++;
					r++;
					continue;
				}
				ans[r - l + 1] = 0;
				int min_top = (int)1e16, min_down = (int)1e16;
				for (int j = l; j < r; j++) {
					assert(A[i][j] == '1');
					min_top = min(min_top, i - top[i][j] + 1);
					min_down = min(min_down, down[i][j] - i + 1);
					ans[j - l + 1] = min(ans[j - l + 1], min_top + min_down - 1);
				}
				l = r;
			}
		}
		for (int i = 1; i <= N; i++) {
			reverse(A[i] + 1, A[i] + 1 + M);
			reverse(top[i] + 1, top[i] + 1 + M);
			reverse(down[i] + 1, down[i] + 1 + M);
		}
	}
	int ret = 0;
	for (int i = 1; i <= M; i++) {
		if (i > 1) ans[i] = min(ans[i], ans[i - 1]);
		assert(ans[i] != (int)1e16);
		ret = max(ret, i * ans[i]);
	}
	cout << ret << '\n';
}

Compilation message

bomb.cpp:29:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   29 | main() {
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 10 ms 26532 KB Output is correct
4 Correct 10 ms 26544 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 0 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 0 ms 468 KB Output is correct
13 Correct 0 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 1 ms 980 KB Output is correct
18 Correct 1 ms 1108 KB Output is correct
19 Correct 1 ms 1364 KB Output is correct
20 Correct 1 ms 1364 KB Output is correct
21 Correct 1 ms 980 KB Output is correct
22 Correct 1 ms 1236 KB Output is correct
23 Correct 1 ms 1492 KB Output is correct
24 Correct 1 ms 1236 KB Output is correct
25 Correct 1 ms 1492 KB Output is correct
26 Correct 1 ms 1492 KB Output is correct
27 Correct 3 ms 4564 KB Output is correct
28 Correct 5 ms 5076 KB Output is correct
29 Correct 6 ms 6356 KB Output is correct
30 Correct 7 ms 7764 KB Output is correct
31 Correct 6 ms 6100 KB Output is correct
32 Correct 7 ms 6996 KB Output is correct
33 Correct 9 ms 8148 KB Output is correct
34 Correct 5 ms 5276 KB Output is correct
35 Correct 8 ms 8148 KB Output is correct
36 Correct 8 ms 8148 KB Output is correct
37 Correct 1 ms 468 KB Output is correct
38 Correct 183 ms 104388 KB Output is correct
39 Correct 1 ms 468 KB Output is correct
40 Correct 29 ms 21584 KB Output is correct
41 Correct 1 ms 468 KB Output is correct
42 Correct 1 ms 1492 KB Output is correct
43 Correct 176 ms 104428 KB Output is correct
44 Correct 8 ms 8148 KB Output is correct
45 Correct 178 ms 104492 KB Output is correct
46 Correct 173 ms 104596 KB Output is correct
47 Correct 171 ms 104464 KB Output is correct
48 Correct 173 ms 104504 KB Output is correct
49 Correct 183 ms 104396 KB Output is correct
50 Correct 170 ms 104504 KB Output is correct
51 Correct 189 ms 104384 KB Output is correct
52 Correct 184 ms 104476 KB Output is correct
53 Correct 182 ms 104524 KB Output is correct
54 Correct 177 ms 104412 KB Output is correct
55 Correct 175 ms 104488 KB Output is correct
56 Correct 190 ms 104580 KB Output is correct
57 Correct 174 ms 104408 KB Output is correct
58 Correct 173 ms 104476 KB Output is correct
59 Correct 173 ms 104500 KB Output is correct
60 Correct 182 ms 104588 KB Output is correct
61 Correct 190 ms 104504 KB Output is correct
62 Correct 176 ms 104440 KB Output is correct
63 Correct 183 ms 104396 KB Output is correct
64 Correct 171 ms 104528 KB Output is correct
65 Correct 187 ms 104396 KB Output is correct
66 Correct 172 ms 104500 KB Output is correct
67 Correct 178 ms 104492 KB Output is correct
68 Correct 173 ms 104432 KB Output is correct
69 Correct 170 ms 104476 KB Output is correct
70 Correct 121 ms 83628 KB Output is correct
71 Correct 164 ms 104408 KB Output is correct
72 Correct 162 ms 104396 KB Output is correct
73 Correct 168 ms 104504 KB Output is correct
74 Correct 162 ms 104580 KB Output is correct
75 Correct 166 ms 104460 KB Output is correct
76 Correct 165 ms 104472 KB Output is correct
77 Correct 172 ms 104396 KB Output is correct
78 Correct 191 ms 104444 KB Output is correct
79 Correct 172 ms 104436 KB Output is correct
80 Correct 172 ms 104432 KB Output is correct
81 Correct 215 ms 104440 KB Output is correct
82 Correct 187 ms 104400 KB Output is correct
83 Correct 169 ms 104584 KB Output is correct
84 Correct 177 ms 104620 KB Output is correct
85 Correct 187 ms 104524 KB Output is correct
86 Correct 183 ms 104516 KB Output is correct
87 Correct 170 ms 104624 KB Output is correct
88 Correct 178 ms 104748 KB Output is correct
89 Correct 179 ms 104524 KB Output is correct
90 Correct 125 ms 83788 KB Output is correct
91 Correct 173 ms 104524 KB Output is correct
92 Correct 176 ms 104636 KB Output is correct
93 Correct 207 ms 104632 KB Output is correct
94 Correct 183 ms 104660 KB Output is correct
95 Correct 179 ms 104684 KB Output is correct
96 Correct 178 ms 104628 KB Output is correct
97 Correct 182 ms 104540 KB Output is correct
98 Correct 191 ms 104632 KB Output is correct
99 Correct 189 ms 104620 KB Output is correct
100 Correct 195 ms 104632 KB Output is correct