답안 #165639

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
165639 2019-11-28T00:03:42 Z qkxwsm Bomb (IZhO17_bomb) C++14
100 / 100
410 ms 56568 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 << up[i][j] << ' ';
	// 	}
	// 	cerr << endl;
	// }
	// FOR(i, 0, N)
	// {
	// 	FOR(j, 0, M)
	// 	{
	// 		cerr << dn[i][j] << ' ';
	// 	}
	// 	cerr << endl;
	// }
	FOR(i, 0, N)
	{
		int sum = 0; pii bound = {0, N - 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, N - 1};
			}
			if (sum > 1) ckmin(dp[sum], bound.se - bound.fi + 1);
			// cerr << sum << ',' << bound.se << ' ' << bound.fi << ' ' << bound.se - bound.fi + 1 << ' ';
		}
		// cerr << endl;
	}
	FOR(i, 0, N)
	{
		int sum = 0; pii bound = {0, N - 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, N - 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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 18 ms 21240 KB Output is correct
4 Correct 18 ms 21240 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 504 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 508 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 2 ms 504 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 2 ms 504 KB Output is 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 1016 KB Output is correct
18 Correct 2 ms 1020 KB Output is correct
19 Correct 3 ms 1144 KB Output is correct
20 Correct 3 ms 1272 KB Output is correct
21 Correct 2 ms 764 KB Output is correct
22 Correct 3 ms 1016 KB Output is correct
23 Correct 3 ms 1272 KB Output is correct
24 Correct 3 ms 1144 KB Output is correct
25 Correct 3 ms 1272 KB Output is correct
26 Correct 3 ms 1272 KB Output is correct
27 Correct 6 ms 3576 KB Output is correct
28 Correct 7 ms 3832 KB Output is correct
29 Correct 8 ms 4728 KB Output is correct
30 Correct 10 ms 5752 KB Output is correct
31 Correct 8 ms 4472 KB Output is correct
32 Correct 8 ms 5112 KB Output is correct
33 Correct 10 ms 5880 KB Output is correct
34 Correct 6 ms 4088 KB Output is correct
35 Correct 10 ms 5880 KB Output is correct
36 Correct 10 ms 5880 KB Output is correct
37 Correct 2 ms 504 KB Output is correct
38 Correct 334 ms 56304 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 306 ms 56568 KB Output is correct
44 Correct 10 ms 5880 KB Output is correct
45 Correct 302 ms 56440 KB Output is correct
46 Correct 305 ms 56420 KB Output is correct
47 Correct 300 ms 56312 KB Output is correct
48 Correct 304 ms 56308 KB Output is correct
49 Correct 308 ms 56312 KB Output is correct
50 Correct 301 ms 56440 KB Output is correct
51 Correct 296 ms 56316 KB Output is correct
52 Correct 297 ms 56456 KB Output is correct
53 Correct 297 ms 56284 KB Output is correct
54 Correct 289 ms 56444 KB Output is correct
55 Correct 289 ms 56304 KB Output is correct
56 Correct 304 ms 56312 KB Output is correct
57 Correct 288 ms 56476 KB Output is correct
58 Correct 286 ms 56312 KB Output is correct
59 Correct 282 ms 56440 KB Output is correct
60 Correct 295 ms 56440 KB Output is correct
61 Correct 313 ms 56308 KB Output is correct
62 Correct 302 ms 56380 KB Output is correct
63 Correct 410 ms 56312 KB Output is correct
64 Correct 283 ms 56312 KB Output is correct
65 Correct 288 ms 56312 KB Output is correct
66 Correct 298 ms 56508 KB Output is correct
67 Correct 299 ms 56356 KB Output is correct
68 Correct 304 ms 56312 KB Output is correct
69 Correct 289 ms 56460 KB Output is correct
70 Correct 183 ms 44264 KB Output is correct
71 Correct 294 ms 56316 KB Output is correct
72 Correct 291 ms 56316 KB Output is correct
73 Correct 285 ms 56440 KB Output is correct
74 Correct 298 ms 56440 KB Output is correct
75 Correct 285 ms 56440 KB Output is correct
76 Correct 290 ms 56312 KB Output is correct
77 Correct 326 ms 56440 KB Output is correct
78 Correct 289 ms 56308 KB Output is correct
79 Correct 290 ms 56312 KB Output is correct
80 Correct 283 ms 56284 KB Output is correct
81 Correct 286 ms 56396 KB Output is correct
82 Correct 295 ms 56440 KB Output is correct
83 Correct 307 ms 56312 KB Output is correct
84 Correct 297 ms 56356 KB Output is correct
85 Correct 285 ms 56312 KB Output is correct
86 Correct 303 ms 56272 KB Output is correct
87 Correct 297 ms 56340 KB Output is correct
88 Correct 289 ms 56404 KB Output is correct
89 Correct 300 ms 56376 KB Output is correct
90 Correct 192 ms 44376 KB Output is correct
91 Correct 290 ms 56056 KB Output is correct
92 Correct 292 ms 56184 KB Output is correct
93 Correct 303 ms 56056 KB Output is correct
94 Correct 291 ms 56184 KB Output is correct
95 Correct 285 ms 56056 KB Output is correct
96 Correct 289 ms 56184 KB Output is correct
97 Correct 305 ms 56316 KB Output is correct
98 Correct 285 ms 56056 KB Output is correct
99 Correct 293 ms 56056 KB Output is correct
100 Correct 297 ms 56080 KB Output is correct