Submission #38849

# Submission time Handle Problem Language Result Execution time Memory
38849 2018-01-07T08:39:12 Z grumpy_gordon Bomb (IZhO17_bomb) C++14
100 / 100
529 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;
			}
		}
	}
	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 3 ms 61440 KB Output is correct
4 Correct 0 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 3 ms 61440 KB Output is correct
28 Correct 0 ms 61440 KB Output is correct
29 Correct 6 ms 61440 KB Output is correct
30 Correct 0 ms 61440 KB Output is correct
31 Correct 3 ms 61440 KB Output is correct
32 Correct 0 ms 61440 KB Output is correct
33 Correct 3 ms 61440 KB Output is correct
34 Correct 0 ms 61440 KB Output is correct
35 Correct 3 ms 61440 KB Output is correct
36 Correct 6 ms 61440 KB Output is correct
37 Correct 0 ms 61440 KB Output is correct
38 Correct 473 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 343 ms 61440 KB Output is correct
44 Correct 3 ms 61440 KB Output is correct
45 Correct 276 ms 61440 KB Output is correct
46 Correct 283 ms 61440 KB Output is correct
47 Correct 323 ms 61440 KB Output is correct
48 Correct 336 ms 61440 KB Output is correct
49 Correct 483 ms 61440 KB Output is correct
50 Correct 276 ms 61440 KB Output is correct
51 Correct 289 ms 61440 KB Output is correct
52 Correct 273 ms 61440 KB Output is correct
53 Correct 313 ms 61440 KB Output is correct
54 Correct 183 ms 61440 KB Output is correct
55 Correct 193 ms 61440 KB Output is correct
56 Correct 436 ms 61440 KB Output is correct
57 Correct 183 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 246 ms 61440 KB Output is correct
61 Correct 483 ms 61440 KB Output is correct
62 Correct 436 ms 61440 KB Output is correct
63 Correct 529 ms 61440 KB Output is correct
64 Correct 189 ms 61440 KB Output is correct
65 Correct 236 ms 61440 KB Output is correct
66 Correct 289 ms 61440 KB Output is correct
67 Correct 273 ms 61440 KB Output is correct
68 Correct 356 ms 61440 KB Output is correct
69 Correct 159 ms 61440 KB Output is correct
70 Correct 63 ms 61440 KB Output is correct
71 Correct 153 ms 61440 KB Output is correct
72 Correct 166 ms 61440 KB Output is correct
73 Correct 169 ms 61440 KB Output is correct
74 Correct 166 ms 61440 KB Output is correct
75 Correct 159 ms 61440 KB Output is correct
76 Correct 183 ms 61440 KB Output is correct
77 Correct 163 ms 61440 KB Output is correct
78 Correct 169 ms 61440 KB Output is correct
79 Correct 103 ms 61440 KB Output is correct
80 Correct 83 ms 61440 KB Output is correct
81 Correct 89 ms 61440 KB Output is correct
82 Correct 169 ms 61440 KB Output is correct
83 Correct 166 ms 61440 KB Output is correct
84 Correct 106 ms 61440 KB Output is correct
85 Correct 166 ms 61440 KB Output is correct
86 Correct 363 ms 61440 KB Output is correct
87 Correct 186 ms 61440 KB Output is correct
88 Correct 193 ms 61440 KB Output is correct
89 Correct 219 ms 61440 KB Output is correct
90 Correct 86 ms 61440 KB Output is correct
91 Correct 213 ms 61440 KB Output is correct
92 Correct 296 ms 61440 KB Output is correct
93 Correct 483 ms 61440 KB Output is correct
94 Correct 309 ms 61440 KB Output is correct
95 Correct 203 ms 61440 KB Output is correct
96 Correct 226 ms 61440 KB Output is correct
97 Correct 493 ms 61440 KB Output is correct
98 Correct 203 ms 61440 KB Output is correct
99 Correct 273 ms 61440 KB Output is correct
100 Correct 409 ms 61440 KB Output is correct