Submission #165610

# Submission time Handle Problem Language Result Execution time Memory
165610 2019-11-27T17:25:00 Z qkxwsm Bomb (IZhO17_bomb) C++14
94 / 100
419 ms 52060 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, N + 1)
	{
		dp[i] = INF;
	}
	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);
	}
	// 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 Incorrect 2 ms 376 KB Output isn't correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 18 ms 21240 KB Output is correct
4 Correct 19 ms 21240 KB Output is correct
5 Incorrect 2 ms 376 KB Output isn't correct
6 Incorrect 2 ms 376 KB Output isn't 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 508 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 16 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 888 KB Output is correct
22 Correct 3 ms 1012 KB Output is correct
23 Correct 3 ms 1268 KB Output is correct
24 Correct 3 ms 1016 KB Output is correct
25 Correct 3 ms 1272 KB Output is correct
26 Correct 3 ms 1272 KB Output is correct
27 Incorrect 6 ms 3548 KB Output isn't correct
28 Correct 7 ms 3756 KB Output is correct
29 Correct 8 ms 4728 KB Output is correct
30 Correct 10 ms 5624 KB Output is correct
31 Correct 8 ms 4472 KB Output is correct
32 Correct 9 ms 5112 KB Output is correct
33 Correct 11 ms 5880 KB Output is correct
34 Correct 7 ms 4088 KB Output is correct
35 Correct 11 ms 5880 KB Output is correct
36 Correct 11 ms 5880 KB Output is correct
37 Correct 2 ms 504 KB Output is correct
38 Correct 301 ms 51316 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 1276 KB Output is correct
43 Correct 419 ms 51368 KB Output is correct
44 Correct 11 ms 6008 KB Output is correct
45 Correct 292 ms 51548 KB Output is correct
46 Correct 300 ms 51448 KB Output is correct
47 Correct 306 ms 51576 KB Output is correct
48 Correct 300 ms 51448 KB Output is correct
49 Correct 305 ms 51560 KB Output is correct
50 Correct 310 ms 51548 KB Output is correct
51 Correct 298 ms 51592 KB Output is correct
52 Correct 304 ms 51576 KB Output is correct
53 Correct 297 ms 51732 KB Output is correct
54 Correct 292 ms 51708 KB Output is correct
55 Correct 284 ms 51676 KB Output is correct
56 Correct 308 ms 51768 KB Output is correct
57 Correct 290 ms 51576 KB Output is correct
58 Correct 287 ms 51636 KB Output is correct
59 Correct 291 ms 51844 KB Output is correct
60 Correct 294 ms 51704 KB Output is correct
61 Correct 302 ms 51708 KB Output is correct
62 Correct 306 ms 51776 KB Output is correct
63 Correct 305 ms 51892 KB Output is correct
64 Correct 295 ms 51844 KB Output is correct
65 Correct 303 ms 51832 KB Output is correct
66 Correct 294 ms 51836 KB Output is correct
67 Correct 308 ms 51804 KB Output is correct
68 Correct 298 ms 51704 KB Output is correct
69 Correct 290 ms 51676 KB Output is correct
70 Correct 187 ms 42124 KB Output is correct
71 Correct 288 ms 51812 KB Output is correct
72 Correct 288 ms 51804 KB Output is correct
73 Correct 287 ms 51848 KB Output is correct
74 Correct 289 ms 51832 KB Output is correct
75 Correct 289 ms 51704 KB Output is correct
76 Correct 290 ms 51840 KB Output is correct
77 Correct 293 ms 51836 KB Output is correct
78 Correct 295 ms 51960 KB Output is correct
79 Correct 287 ms 51764 KB Output is correct
80 Correct 290 ms 51832 KB Output is correct
81 Correct 293 ms 51960 KB Output is correct
82 Correct 295 ms 51884 KB Output is correct
83 Correct 299 ms 51832 KB Output is correct
84 Correct 290 ms 51960 KB Output is correct
85 Correct 289 ms 51848 KB Output is correct
86 Correct 305 ms 52060 KB Output is correct
87 Correct 285 ms 51908 KB Output is correct
88 Correct 319 ms 51812 KB Output is correct
89 Correct 298 ms 51832 KB Output is correct
90 Correct 202 ms 42304 KB Output is correct
91 Correct 289 ms 51828 KB Output is correct
92 Correct 302 ms 51752 KB Output is correct
93 Correct 302 ms 51812 KB Output is correct
94 Correct 305 ms 51780 KB Output is correct
95 Correct 285 ms 51704 KB Output is correct
96 Correct 295 ms 51712 KB Output is correct
97 Correct 307 ms 51796 KB Output is correct
98 Correct 289 ms 51836 KB Output is correct
99 Correct 300 ms 51704 KB Output is correct
100 Correct 318 ms 51740 KB Output is correct