답안 #574047

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
574047 2022-06-07T15:57:28 Z vovamr Bomb (IZhO17_bomb) C++17
100 / 100
652 ms 74244 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fi first
#define se second
#define ll long long
#define ld long double
#define sz(x) ((int)(x).size())
#define all(x) 	(x).begin(), (x).end()
#define pb push_back
#define mpp make_pair
#define ve vector
using namespace std;
using namespace __gnu_pbds;
template<class T> using oset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const ll inf = 1e18; const int iinf = 1e9;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T> inline bool chmin(T& a, T b) { return (a > b ? a = b, 1 : 0); }
template <typename T> inline bool chmax(T& a, T b) { return (a < b ? a = b, 1 : 0); }
 
inline void solve() {
	int n, m;
	cin >> n >> m;
	ve<ve<int>> a(n, ve<int>(m));
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			char x;
			cin >> x;
			a[i][j] = x - '0';
		}
	}
 
	ve<int> mx(m + 2, iinf);
	for (int rep = 0; rep < 2; ++rep) {
		ve<ve<int>> dp1(n, ve<int> (m)), dp2(n, ve<int> (m));
		for (int j = 0; j < m; ++j) {
			for (int i = 0; i < n; ++i) {
				dp1[i][j] = (a[i][j] ? 1 + (!i ? 0 : dp1[i - 1][j]) : 0);
			}
			for (int i = n - 1; ~i; --i) {
				dp2[i][j] = (a[i][j] ? 1 + (i + 1 == n ? 0 : dp2[i + 1][j]) : 0);
				if (a[i][j]) chmin(mx[1], dp1[i][j] + dp2[i][j] - 1);
			}
		}
 
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < m; ) {
				if (!a[i][j]) { ++j; continue; }
 
				int p = j;
				while (j < m && a[i][p]) ++p;
 
				int a = iinf, b = iinf;
				for (int k = j; k < p; ++k) {
					chmin(a, dp1[i][k]); chmin(b, dp2[i][k]);
					chmin(mx[k - j + 1], a + b - 1);
				}
				chmin(mx[p - j + 1], 0);
 
				j = p;
			}
		}
 
		for (int i = 0; i < n; ++i) reverse(all(a[i]));
	}
 
	ll ans = 0;
	for (int i = 1; i <= m; ++i) {
		chmin(mx[i], mx[i - 1]);
		chmax(ans, i * 1ll * mx[i]);
	}
	cout << ans;
}
 
signed main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int q = 1; // cin >> q;
	while (q--) solve();
	cerr << fixed << setprecision(3) << "Time execution: " << (double)clock() / CLOCKS_PER_SEC << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 724 KB Output is correct
4 Correct 1 ms 724 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 228 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 3 ms 1236 KB Output is correct
28 Correct 5 ms 1620 KB Output is correct
29 Correct 5 ms 1764 KB Output is correct
30 Correct 7 ms 2560 KB Output is correct
31 Correct 6 ms 2088 KB Output is correct
32 Correct 6 ms 2124 KB Output is correct
33 Correct 8 ms 2696 KB Output is correct
34 Correct 3 ms 1296 KB Output is correct
35 Correct 9 ms 2696 KB Output is correct
36 Correct 10 ms 2724 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 626 ms 74080 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 63 ms 9452 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 586 ms 74064 KB Output is correct
44 Correct 8 ms 2696 KB Output is correct
45 Correct 607 ms 74032 KB Output is correct
46 Correct 597 ms 74000 KB Output is correct
47 Correct 610 ms 74020 KB Output is correct
48 Correct 619 ms 74016 KB Output is correct
49 Correct 644 ms 74000 KB Output is correct
50 Correct 597 ms 74076 KB Output is correct
51 Correct 606 ms 74052 KB Output is correct
52 Correct 602 ms 74012 KB Output is correct
53 Correct 628 ms 74024 KB Output is correct
54 Correct 603 ms 74028 KB Output is correct
55 Correct 585 ms 74080 KB Output is correct
56 Correct 652 ms 74004 KB Output is correct
57 Correct 583 ms 74024 KB Output is correct
58 Correct 567 ms 74040 KB Output is correct
59 Correct 566 ms 74012 KB Output is correct
60 Correct 585 ms 74004 KB Output is correct
61 Correct 642 ms 74032 KB Output is correct
62 Correct 618 ms 74056 KB Output is correct
63 Correct 629 ms 74244 KB Output is correct
64 Correct 582 ms 74056 KB Output is correct
65 Correct 610 ms 74024 KB Output is correct
66 Correct 622 ms 74000 KB Output is correct
67 Correct 624 ms 73952 KB Output is correct
68 Correct 598 ms 74012 KB Output is correct
69 Correct 594 ms 74012 KB Output is correct
70 Correct 342 ms 47548 KB Output is correct
71 Correct 552 ms 74004 KB Output is correct
72 Correct 549 ms 74048 KB Output is correct
73 Correct 558 ms 74008 KB Output is correct
74 Correct 609 ms 74068 KB Output is correct
75 Correct 575 ms 73980 KB Output is correct
76 Correct 565 ms 74000 KB Output is correct
77 Correct 554 ms 74040 KB Output is correct
78 Correct 571 ms 74052 KB Output is correct
79 Correct 547 ms 74048 KB Output is correct
80 Correct 516 ms 74012 KB Output is correct
81 Correct 519 ms 73964 KB Output is correct
82 Correct 559 ms 74004 KB Output is correct
83 Correct 579 ms 74008 KB Output is correct
84 Correct 540 ms 74020 KB Output is correct
85 Correct 554 ms 73916 KB Output is correct
86 Correct 623 ms 74000 KB Output is correct
87 Correct 564 ms 74016 KB Output is correct
88 Correct 565 ms 74008 KB Output is correct
89 Correct 578 ms 74016 KB Output is correct
90 Correct 358 ms 47480 KB Output is correct
91 Correct 591 ms 74060 KB Output is correct
92 Correct 593 ms 74024 KB Output is correct
93 Correct 641 ms 74040 KB Output is correct
94 Correct 603 ms 74080 KB Output is correct
95 Correct 586 ms 74028 KB Output is correct
96 Correct 572 ms 74004 KB Output is correct
97 Correct 633 ms 74084 KB Output is correct
98 Correct 597 ms 74004 KB Output is correct
99 Correct 574 ms 74084 KB Output is correct
100 Correct 617 ms 74004 KB Output is correct