Submission #165611

# Submission time Handle Problem Language Result Execution time Memory
165611 2019-11-27T17:37:07 Z qkxwsm Bomb (IZhO17_bomb) C++14
97 / 100
386 ms 52472 KB
#include <bits/stdc++.h>

using namespace std;

template<class T, class U>
void ckmin(T &a, U b)
{
	if (a > b) a = b;
}
template<class T, class U>
void ckmax(T &a, U b)
{
	if (a < b) a = b;
}

#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)
#define SZ(x) ((int) ((x).size()))
#define ALL(x) (x).begin(), (x).end()
#define MAXN 2513
#define INF 1000000007

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;

int N, M;
bitset<MAXN> grid[MAXN];
int up[MAXN][MAXN], dn[MAXN][MAXN];
int dp[MAXN];
int ans;
int width = INF;

int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	cout << fixed << setprecision(12);
	cerr << fixed << setprecision(4);
	cin >> N >> M;
	FOR(i, 0, N)
	{
		string temps; cin >> temps;
		FOR(j, 0, M)
		{
			grid[i][j] = (temps[j] == '1');
		}
	}
	//length of shortest vertical strip.
	FOR(i, 0, M + 1)
	{
		dp[i] = INF;
	}
	// cerr << dp[2] << endl;
	FOR(i, 0, M)
	{
		int sum = 0;
		FOR(j, 0, N)
		{
			if (grid[j][i]) sum++;
			else
			{
				if (sum) ckmin(dp[1], sum);
				sum = 0;
			}
		}
		if (sum) ckmin(dp[1], sum);
	}
	FOR(i, 0, N)
	{
		int sum = 0;
		FOR(j, 0, M)
		{
			if (grid[i][j]) sum++;
			else
			{
				if (sum) ckmin(width, sum);
				sum = 0;
			}
		}
		if (sum) ckmin(width, sum);
	}
	if (width >= INF)
	{
		cout << N * M << '\n';
		return 0;
	}
	// cerr << dp[1] << endl;
	FOR(j, 0, M)
	{
		FOR(i, 0, N)
		{
			if (!grid[i][j]) up[i][j] = i + 1;
			else up[i][j] = (i == 0 ? 0 : up[i - 1][j]);
		}
		FORD(i, N, 0)
		{
			if (!grid[i][j]) dn[i][j] = i - 1;
			else dn[i][j] = (i == N - 1 ? N - 1 : dn[i + 1][j]);
		}
	}
	// FOR(i, 0, N)
	// {
	// 	FOR(j, 0, M)
	// 	{
	// 		cerr << dn[i][j] << ' ';
	// 	}
	// 	cerr << endl;
	// }
	FOR(i, 0, N)
	{
		int sum = 0; pii bound = {0, M - 1};
		FOR(j, 0, M)
		{
			if (grid[i][j])
			{
				sum++;
				ckmin(bound.se, dn[i][j]);
				ckmax(bound.fi, up[i][j]);
			}
			else
			{
				sum = 0;
				bound = {0, M - 1};
			}
			if (sum > 1) ckmin(dp[sum], bound.se - bound.fi + 1);
			// cerr << sum << ',' << bound.se - bound.fi + 1 << ' ';
		}
		// cerr << endl;
	}
	FOR(i, 0, N)
	{
		int sum = 0; pii bound = {0, M - 1};
		FORD(j, M, 0)
		{
			if (grid[i][j])
			{
				sum++;
				ckmin(bound.se, dn[i][j]);
				ckmax(bound.fi, up[i][j]);
			}
			else
			{
				sum = 0;
				bound = {0, M - 1};
			}
			if (sum > 1) ckmin(dp[sum], bound.se - bound.fi + 1);
			// cerr << sum << ',' << bound.se - bound.fi + 1 << ' ';
		}
		// cerr << endl;
	}
	FOR(i, 1, width + 1)
	{
		ckmin(dp[i], dp[1]);
		ckmax(ans, dp[i] * i);
		// cerr << dp[i] << endl;
	}
	cout << ans << '\n';
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 25 ms 21240 KB Output is correct
4 Correct 20 ms 21368 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 2 ms 504 KB Output is correct
10 Incorrect 2 ms 504 KB Output isn't correct
11 Correct 2 ms 504 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Incorrect 2 ms 504 KB Output isn't correct
14 Correct 2 ms 504 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Correct 3 ms 888 KB Output is correct
18 Correct 3 ms 1016 KB Output is correct
19 Correct 3 ms 1144 KB Output is correct
20 Correct 3 ms 1144 KB Output is correct
21 Correct 3 ms 804 KB Output is correct
22 Correct 3 ms 1016 KB Output is correct
23 Correct 3 ms 1328 KB Output is correct
24 Correct 3 ms 1148 KB Output is correct
25 Correct 3 ms 1272 KB Output is correct
26 Correct 3 ms 1272 KB Output is correct
27 Incorrect 7 ms 3492 KB Output isn't correct
28 Correct 7 ms 3704 KB Output is correct
29 Correct 8 ms 4772 KB Output is correct
30 Correct 10 ms 5624 KB Output is correct
31 Correct 8 ms 4400 KB Output is correct
32 Correct 9 ms 5112 KB Output is correct
33 Correct 10 ms 5880 KB Output is correct
34 Correct 7 ms 4088 KB Output is correct
35 Correct 10 ms 5880 KB Output is correct
36 Correct 11 ms 5880 KB Output is correct
37 Correct 3 ms 504 KB Output is correct
38 Correct 304 ms 52472 KB Output is correct
39 Correct 2 ms 504 KB Output is correct
40 Correct 33 ms 14456 KB Output is correct
41 Correct 2 ms 504 KB Output is correct
42 Correct 3 ms 1272 KB Output is correct
43 Correct 307 ms 52120 KB Output is correct
44 Correct 11 ms 5880 KB Output is correct
45 Correct 305 ms 52200 KB Output is correct
46 Correct 305 ms 51932 KB Output is correct
47 Correct 303 ms 52088 KB Output is correct
48 Correct 302 ms 52060 KB Output is correct
49 Correct 302 ms 51960 KB Output is correct
50 Correct 305 ms 52088 KB Output is correct
51 Correct 294 ms 51960 KB Output is correct
52 Correct 299 ms 51832 KB Output is correct
53 Correct 307 ms 51804 KB Output is correct
54 Correct 299 ms 51756 KB Output is correct
55 Correct 299 ms 51932 KB Output is correct
56 Correct 310 ms 51896 KB Output is correct
57 Correct 302 ms 51960 KB Output is correct
58 Correct 297 ms 51980 KB Output is correct
59 Correct 297 ms 51968 KB Output is correct
60 Correct 304 ms 52088 KB Output is correct
61 Correct 306 ms 52008 KB Output is correct
62 Correct 302 ms 51708 KB Output is correct
63 Correct 311 ms 51792 KB Output is correct
64 Correct 306 ms 51832 KB Output is correct
65 Correct 306 ms 51704 KB Output is correct
66 Correct 303 ms 51976 KB Output is correct
67 Correct 306 ms 51864 KB Output is correct
68 Correct 306 ms 51852 KB Output is correct
69 Correct 304 ms 51836 KB Output is correct
70 Correct 195 ms 41720 KB Output is correct
71 Correct 293 ms 51888 KB Output is correct
72 Correct 304 ms 51832 KB Output is correct
73 Correct 290 ms 51704 KB Output is correct
74 Correct 289 ms 51820 KB Output is correct
75 Correct 296 ms 51832 KB Output is correct
76 Correct 302 ms 51708 KB Output is correct
77 Correct 295 ms 51704 KB Output is correct
78 Correct 290 ms 51760 KB Output is correct
79 Correct 284 ms 51820 KB Output is correct
80 Correct 289 ms 51576 KB Output is correct
81 Correct 281 ms 51448 KB Output is correct
82 Correct 361 ms 51824 KB Output is correct
83 Correct 286 ms 51640 KB Output is correct
84 Correct 285 ms 51676 KB Output is correct
85 Correct 289 ms 51588 KB Output is correct
86 Correct 298 ms 51420 KB Output is correct
87 Correct 297 ms 51548 KB Output is correct
88 Correct 386 ms 51448 KB Output is correct
89 Correct 291 ms 51548 KB Output is correct
90 Correct 188 ms 41464 KB Output is correct
91 Correct 295 ms 51212 KB Output is correct
92 Correct 320 ms 51320 KB Output is correct
93 Correct 304 ms 51396 KB Output is correct
94 Correct 292 ms 51192 KB Output is correct
95 Correct 296 ms 51440 KB Output is correct
96 Correct 291 ms 51192 KB Output is correct
97 Correct 300 ms 51192 KB Output is correct
98 Correct 287 ms 51320 KB Output is correct
99 Correct 291 ms 51420 KB Output is correct
100 Correct 296 ms 51192 KB Output is correct