답안 #37225

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
37225 2017-12-22T17:49:11 Z alenam0161 Bomb (IZhO17_bomb) C++14
0 / 100
0 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:32:31: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen("bomb.in","r",stdin);
                               ^
bomb.cpp:33:33: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen("bomb.out","w",stdout);
                                 ^
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]);
                     ^
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
2 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
3 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
4 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
5 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
6 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
7 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
8 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
9 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
10 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
11 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
12 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
13 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
14 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
15 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
16 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
17 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
18 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
19 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
20 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
21 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
22 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
23 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
24 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
25 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
26 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
27 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
28 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
29 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
30 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
31 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
32 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
33 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
34 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
35 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
36 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
37 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
38 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
39 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
40 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
41 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
42 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
43 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
44 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
45 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
46 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
47 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
48 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
49 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
50 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
51 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
52 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
53 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
54 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
55 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
56 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
57 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
58 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
59 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
60 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
61 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
62 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
63 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
64 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
65 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
66 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
67 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
68 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
69 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
70 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
71 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
72 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
73 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
74 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
75 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
76 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
77 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
78 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
79 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
80 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
81 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
82 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
83 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
84 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
85 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
86 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
87 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
88 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
89 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
90 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
91 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
92 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
93 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
94 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
95 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
96 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
97 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
98 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
99 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
100 Runtime error 0 ms 61440 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)