Submission #37226

# Submission time Handle Problem Language Result Execution time Memory
37226 2017-12-22T17:49:48 Z alenam0161 Bomb (IZhO17_bomb) C++14
100 / 100
496 ms 61440 KB
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <queue>

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long double ld;

using namespace std;
const int MAXN = 2600;

int n, m;
char s[MAXN][MAXN];
int ans[MAXN];
int up[MAXN][MAXN];
int dw[MAXN][MAXN];

int main() {
 // freopen("bomb.in","r",stdin);
 // freopen("bomb.out","w",stdout);
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; ++i)
		scanf(" %s", s[i]);
	int mxh = n;
	int mxw = m;
	for (int i = 0; i < n; ++i) {
		int cnt = 0;
		for (int j = 0; j < m; ++j) {
			if (s[i][j] == '1')
				++cnt;
			if (s[i][j] == '1' && (j == m - 1 || s[i][j + 1] == '0')) {
				mxw = min(mxw, cnt);
				cnt = 0;
			}
		}
	}
	for (int i = 0; i < m; ++i) {
		int cnt = 0;
		for (int j = 0; j < n; ++j) {
			if (s[j][i] == '1')
				++cnt, up[j][i] = cnt;
			if (s[j][i] == '1' && (j == n - 1 || s[j + 1][i] == '0')) {
				mxh = min(mxh, cnt);
				cnt = 0;
			}
		}
	}
	for (int i = 0; i < m; ++i) {
		int cnt = 0;
		for (int j = n - 1; j >= 0; --j) {
			if (s[j][i] == '1')
				++cnt, dw[j][i] = cnt;
			else
				cnt = 0;
		}
	}
	for (int i = 0; i <= mxw; ++i)
		ans[i] = mxh;

	for (int i = 0; i < n; ++i) {
		int a = MAXN;
		int b = MAXN;
		int cnt = 0;
		for (int j = 0; j < m; ++j) {
			if (s[i][j] == '1') {
				a = min(a, up[i][j]);
				b = min(b, dw[i][j]);
				++cnt;
				ans[cnt] = min(ans[cnt], a + b - 1);
			}
			else {
				a = MAXN;
				b = MAXN;
				cnt = 0;
			}
		}
	}

	for (int i = 0; i < n; ++i) {
		int a = MAXN;
		int b = MAXN;
		int cnt = 0;
		for (int j = m - 1; j >= 0; --j) {
			if (s[i][j] == '1') {
				a = min(a, up[i][j]);
				b = min(b, dw[i][j]);
				++cnt;
				ans[cnt] = min(ans[cnt], a + b - 1);
			}
			else {
				a = MAXN;
				b = MAXN;
				cnt = 0;
			}
		}
	}

	for (int i = 1; i <= mxw; ++i)
		ans[i] = min(ans[i], ans[i - 1]);
	int mh = 0;
	int mw = 0;
	for (int i = 1; i <= mxw; ++i)
		if (mh * mw < i * ans[i])
			mw = i, mh = ans[i];
	cout << mh * mw << "\n";

	return 0;
}

Compilation message

bomb.cpp: In function 'int main()':
bomb.cpp:34:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &m);
                       ^
bomb.cpp:36:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf(" %s", s[i]);
                     ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 61440 KB Output is correct
2 Correct 0 ms 61440 KB Output is correct
3 Correct 6 ms 61440 KB Output is correct
4 Correct 3 ms 61440 KB Output is correct
5 Correct 0 ms 61440 KB Output is correct
6 Correct 0 ms 61440 KB Output is correct
7 Correct 0 ms 61440 KB Output is correct
8 Correct 0 ms 61440 KB Output is correct
9 Correct 0 ms 61440 KB Output is correct
10 Correct 0 ms 61440 KB Output is correct
11 Correct 0 ms 61440 KB Output is correct
12 Correct 0 ms 61440 KB Output is correct
13 Correct 0 ms 61440 KB Output is correct
14 Correct 0 ms 61440 KB Output is correct
15 Correct 0 ms 61440 KB Output is correct
16 Correct 0 ms 61440 KB Output is correct
17 Correct 0 ms 61440 KB Output is correct
18 Correct 0 ms 61440 KB Output is correct
19 Correct 0 ms 61440 KB Output is correct
20 Correct 0 ms 61440 KB Output is correct
21 Correct 0 ms 61440 KB Output is correct
22 Correct 0 ms 61440 KB Output is correct
23 Correct 0 ms 61440 KB Output is correct
24 Correct 0 ms 61440 KB Output is correct
25 Correct 0 ms 61440 KB Output is correct
26 Correct 0 ms 61440 KB Output is correct
27 Correct 0 ms 61440 KB Output is correct
28 Correct 0 ms 61440 KB Output is correct
29 Correct 3 ms 61440 KB Output is correct
30 Correct 3 ms 61440 KB Output is correct
31 Correct 3 ms 61440 KB Output is correct
32 Correct 3 ms 61440 KB Output is correct
33 Correct 0 ms 61440 KB Output is correct
34 Correct 0 ms 61440 KB Output is correct
35 Correct 0 ms 61440 KB Output is correct
36 Correct 0 ms 61440 KB Output is correct
37 Correct 0 ms 61440 KB Output is correct
38 Correct 426 ms 61440 KB Output is correct
39 Correct 0 ms 61440 KB Output is correct
40 Correct 19 ms 61440 KB Output is correct
41 Correct 0 ms 61440 KB Output is correct
42 Correct 0 ms 61440 KB Output is correct
43 Correct 319 ms 61440 KB Output is correct
44 Correct 0 ms 61440 KB Output is correct
45 Correct 313 ms 61440 KB Output is correct
46 Correct 293 ms 61440 KB Output is correct
47 Correct 309 ms 61440 KB Output is correct
48 Correct 306 ms 61440 KB Output is correct
49 Correct 496 ms 61440 KB Output is correct
50 Correct 313 ms 61440 KB Output is correct
51 Correct 339 ms 61440 KB Output is correct
52 Correct 319 ms 61440 KB Output is correct
53 Correct 299 ms 61440 KB Output is correct
54 Correct 179 ms 61440 KB Output is correct
55 Correct 196 ms 61440 KB Output is correct
56 Correct 439 ms 61440 KB Output is correct
57 Correct 179 ms 61440 KB Output is correct
58 Correct 169 ms 61440 KB Output is correct
59 Correct 156 ms 61440 KB Output is correct
60 Correct 253 ms 61440 KB Output is correct
61 Correct 426 ms 61440 KB Output is correct
62 Correct 413 ms 61440 KB Output is correct
63 Correct 443 ms 61440 KB Output is correct
64 Correct 186 ms 61440 KB Output is correct
65 Correct 283 ms 61440 KB Output is correct
66 Correct 239 ms 61440 KB Output is correct
67 Correct 276 ms 61440 KB Output is correct
68 Correct 296 ms 61440 KB Output is correct
69 Correct 156 ms 61440 KB Output is correct
70 Correct 76 ms 61440 KB Output is correct
71 Correct 119 ms 61440 KB Output is correct
72 Correct 149 ms 61440 KB Output is correct
73 Correct 133 ms 61440 KB Output is correct
74 Correct 176 ms 61440 KB Output is correct
75 Correct 146 ms 61440 KB Output is correct
76 Correct 143 ms 61440 KB Output is correct
77 Correct 163 ms 61440 KB Output is correct
78 Correct 176 ms 61440 KB Output is correct
79 Correct 66 ms 61440 KB Output is correct
80 Correct 89 ms 61440 KB Output is correct
81 Correct 83 ms 61440 KB Output is correct
82 Correct 206 ms 61440 KB Output is correct
83 Correct 226 ms 61440 KB Output is correct
84 Correct 79 ms 61440 KB Output is correct
85 Correct 189 ms 61440 KB Output is correct
86 Correct 426 ms 61440 KB Output is correct
87 Correct 206 ms 61440 KB Output is correct
88 Correct 199 ms 61440 KB Output is correct
89 Correct 246 ms 61440 KB Output is correct
90 Correct 99 ms 61440 KB Output is correct
91 Correct 216 ms 61440 KB Output is correct
92 Correct 269 ms 61440 KB Output is correct
93 Correct 479 ms 61440 KB Output is correct
94 Correct 309 ms 61440 KB Output is correct
95 Correct 166 ms 61440 KB Output is correct
96 Correct 196 ms 61440 KB Output is correct
97 Correct 409 ms 61440 KB Output is correct
98 Correct 213 ms 61440 KB Output is correct
99 Correct 203 ms 61440 KB Output is correct
100 Correct 376 ms 61440 KB Output is correct