답안 #93237

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
93237 2019-01-07T10:29:07 Z Abelyan Bomb (IZhO17_bomb) C++17
75 / 100
215 ms 56952 KB
#include <iostream>
#include <algorithm>
#include <climits>
#include <cassert>
using namespace std;

typedef long long ll;
typedef long double ld;

#define fr first
#define sc second
#define FOR(i, a) for (int i = 0; i < (a); i++)
#define F0R(i, a, b) for (int i = (a); i <= (b); i++)
#define FORd(i,a) for (int i = (a)-1; i >= 0; i--)
#define F0Rd(i,a,b) for (int i = (b); i >= (a); i--)
#define trav(a, x) for (auto& a : x)

const int N = 2506;
char c[N][N];
int prdz[N][N], praj[N][N], ans1, ans2, pr[N];

void ad(int a, int b){
	//cout << a << " " << b << endl;
	if (a > ans2)a=ans2;
	if (b > ans1)b = ans1;
	pr[a] = min(pr[a], b);
}

int main(){
	ios_base::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	//assert(n <= 20 && m <= 20);
	for (int i = 0; i<n; i++){
		cin >> c[i];
		pr[i] = INT_MAX;
	}
	pr[n] = INT_MAX;
	int mn = INT_MAX;
	for (int i = 0; i<n; i++){
		int tv = 0;
		for (int j = 0; j<m; j++){
			if (c[i][j] == '1'){
				if (j == 0)prdz[i][j] = 1;
				else prdz[i][j] = prdz[i][j - 1] + 1;
				tv++;
			}
			else if (tv != 0){
				mn = min(mn, tv);
				tv = 0;
			}
		}
		for (int j = m - 1; j >= 0; j--){
			if (c[i][j] == '1'){
				praj[i][j] = praj[i][j + 1] + 1;
			}
		}
		if (tv != 0)mn = min(mn, tv);
	}
	ans1 = mn;
	mn = INT_MAX;
	for (int j = 0; j<m; j++){
		int tv = 0;
		for (int i = 0; i<n; i++){
			if (c[i][j] == '1'){
				tv++;
			}
			else if (tv != 0){
				mn = min(mn, tv);
				tv = 0;
			}
		}
		if (tv != 0)mn = min(mn, tv);
	}
	ans2 = mn;
	//cout << ans1 << " " << ans2 << endl;
	for (int j = 0; j < m; j++){
		for (int i = 0; i < n; i++){
			if (c[i][j] == '1' && (j == 0 || c[i][j - 1] == '0')){
				int ans = INT_MAX, k = 0;
				while (i<n && c[i][j] == '1'){
					k++;
					ans = min(ans, praj[i][j]);
					ad(k, ans);
					i++;
				}
				i--;
			}
			else if (c[i][j] == '1' && (j == m - 1 || c[i][j + 1] == '0')){
				int ans = INT_MAX, k = 0;
				while (i<n && c[i][j] == '1'){
					k++;
					ans = min(ans, prdz[i][j]);
					ad(k, ans);
					i++;
				}
				i--;
			}
		}
	}
	for (int j = 0; j<m; j++){
		for (int i = n - 1; i >= 0; i--){
			if (c[i][j] == '1' && (j == 0 || c[i][j - 1] == '0')){
				int ans = INT_MAX, k = 0;
				while (i>=0 && c[i][j] == '1'){
					k++;
					ans = min(ans, praj[i][j]);
					ad(k, ans);
					i--;
				}
				i++;
			}
			else if (c[i][j] == '1' && (j == m - 1 || c[i][j + 1] == '0')){
				int ans = INT_MAX, k = 0;
				while (i>=0 && c[i][j] == '1'){
					k++;
					ans = min(ans, prdz[i][j]);
					ad(k, ans);
					i--;
				}
				i++;
			}
		}
	}
	int verj = 1;
	for (int i = 1; i <= n; i++){
		if (pr[i] == INT_MAX)continue;
		verj = max(verj, i*pr[i]);
	}
	cout << verj << endl;
	return 0;
}
/*
5 6
001000
111110
111110
111110
000100
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 24 ms 26616 KB Output is correct
4 Correct 24 ms 26616 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 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 476 KB Output is correct
10 Incorrect 2 ms 504 KB Output isn't correct
11 Correct 2 ms 504 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 2 ms 508 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Incorrect 3 ms 1016 KB Output isn't correct
18 Correct 2 ms 760 KB Output is correct
19 Correct 2 ms 1016 KB Output is correct
20 Correct 2 ms 1016 KB Output is correct
21 Correct 2 ms 632 KB Output is correct
22 Correct 2 ms 760 KB Output is correct
23 Correct 2 ms 1016 KB Output is correct
24 Correct 2 ms 1016 KB Output is correct
25 Correct 3 ms 1400 KB Output is correct
26 Incorrect 2 ms 1400 KB Output isn't correct
27 Incorrect 5 ms 4088 KB Output isn't correct
28 Correct 3 ms 1528 KB Output is correct
29 Incorrect 7 ms 5240 KB Output isn't correct
30 Correct 7 ms 4348 KB Output is correct
31 Correct 5 ms 3192 KB Output is correct
32 Correct 6 ms 4224 KB Output is correct
33 Correct 7 ms 5368 KB Output is correct
34 Correct 4 ms 1784 KB Output is correct
35 Correct 5 ms 2168 KB Output is correct
36 Incorrect 9 ms 6776 KB Output isn't correct
37 Correct 2 ms 632 KB Output is correct
38 Correct 156 ms 56440 KB Output is correct
39 Correct 2 ms 708 KB Output is correct
40 Incorrect 25 ms 15992 KB Output isn't correct
41 Incorrect 2 ms 504 KB Output isn't correct
42 Correct 3 ms 1400 KB Output is correct
43 Correct 215 ms 52856 KB Output is correct
44 Correct 9 ms 6264 KB Output is correct
45 Correct 179 ms 54264 KB Output is correct
46 Correct 159 ms 56796 KB Output is correct
47 Correct 166 ms 54264 KB Output is correct
48 Incorrect 159 ms 56828 KB Output isn't correct
49 Incorrect 191 ms 56952 KB Output isn't correct
50 Incorrect 153 ms 56840 KB Output isn't correct
51 Incorrect 156 ms 56772 KB Output isn't correct
52 Incorrect 158 ms 56680 KB Output isn't correct
53 Incorrect 164 ms 56192 KB Output isn't correct
54 Incorrect 128 ms 43484 KB Output isn't correct
55 Incorrect 138 ms 41720 KB Output isn't correct
56 Correct 167 ms 56808 KB Output is correct
57 Incorrect 128 ms 36856 KB Output isn't correct
58 Incorrect 132 ms 41708 KB Output isn't correct
59 Incorrect 127 ms 38728 KB Output isn't correct
60 Correct 173 ms 48636 KB Output is correct
61 Correct 183 ms 56824 KB Output is correct
62 Correct 149 ms 56824 KB Output is correct
63 Correct 144 ms 56824 KB Output is correct
64 Correct 128 ms 39672 KB Output is correct
65 Incorrect 144 ms 55780 KB Output isn't correct
66 Incorrect 137 ms 52644 KB Output isn't correct
67 Incorrect 138 ms 56836 KB Output isn't correct
68 Incorrect 143 ms 56952 KB Output isn't correct
69 Incorrect 97 ms 36428 KB Output isn't correct
70 Correct 48 ms 16448 KB Output is correct
71 Correct 85 ms 28920 KB Output is correct
72 Correct 92 ms 33528 KB Output is correct
73 Correct 166 ms 34040 KB Output is correct
74 Correct 97 ms 36856 KB Output is correct
75 Correct 99 ms 38520 KB Output is correct
76 Correct 113 ms 39800 KB Output is correct
77 Correct 128 ms 40312 KB Output is correct
78 Correct 108 ms 40696 KB Output is correct
79 Correct 93 ms 13120 KB Output is correct
80 Correct 100 ms 14384 KB Output is correct
81 Correct 91 ms 14692 KB Output is correct
82 Correct 102 ms 43044 KB Output is correct
83 Correct 129 ms 43256 KB Output is correct
84 Correct 59 ms 8392 KB Output is correct
85 Correct 104 ms 42104 KB Output is correct
86 Correct 140 ms 55720 KB Output is correct
87 Correct 126 ms 41028 KB Output is correct
88 Correct 126 ms 41976 KB Output is correct
89 Correct 136 ms 50936 KB Output is correct
90 Correct 71 ms 30676 KB Output is correct
91 Correct 139 ms 46036 KB Output is correct
92 Correct 120 ms 47720 KB Output is correct
93 Correct 137 ms 54776 KB Output is correct
94 Correct 142 ms 49380 KB Output is correct
95 Correct 111 ms 43256 KB Output is correct
96 Correct 107 ms 42972 KB Output is correct
97 Correct 141 ms 55672 KB Output is correct
98 Correct 108 ms 42792 KB Output is correct
99 Correct 114 ms 49076 KB Output is correct
100 Correct 131 ms 54392 KB Output is correct