답안 #93251

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
93251 2019-01-07T11:01:39 Z Abelyan Bomb (IZhO17_bomb) C++17
99 / 100
206 ms 60228 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){
	if (a > ans2)return;
	if (b > ans1)b = ans1;
	pr[a] = min(pr[a], b);
}

int main(){
	ios_base::sync_with_stdio(false);
	//freopen("tests/01", "r", stdin);
	int n, m;
	cin >> n >> m;
	//assert(n == 1 && m == 20);
	for (int i = 0; i<n; i++){
		//if (i == 56)cout << "hi" << endl;
		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 == 3)cout <<i<< endl;
		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;
	//cout << c[31] << 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') && (i == 0 || c[i - 1][j] == '0')){
				int ans = INT_MAX, k = 0;
				while (i<n && c[i][j] == '1'){
					k++;
					ans = min(ans, praj[i][j]);
					//if (ans == 1 && k<=3)cout << i << " " << j << " " << praj[i][j] << " " << k << endl;
					ad(k, ans);
					i++;
				}
				i--;
			}
			else if (c[i][j] == '1' && (j == m - 1 || c[i][j + 1] == '0') && (i == 0 || c[i - 1][j] == '0')){
				int ans = INT_MAX, k = 0;
				while (i<n && c[i][j] == '1'){
					k++;
					ans = min(ans, prdz[i][j]);
					//if (ans == 1 && k<=3)cout << i << " " << j << " " << praj[i][j] << " " << k << endl;
					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') && (i == n - 1 || c[i + 1][j] == '0')){
				int ans = INT_MAX, k = 0;
				while (i>=0 && c[i][j] == '1'){
					k++;
					ans = min(ans, praj[i][j]);
					//if (ans == 1 && k<=3)cout << i << " " << j << " " << praj[i][j] << " " << k << endl;
					ad(k, ans);
					i--;
				}
				i++;
			}
			else if (c[i][j] == '1' && (j == m - 1 || c[i][j + 1] == '0') && (i==n-1 || c[i+1][j]=='0')){
				int ans = INT_MAX, k = 0;
				while (i>=0 && c[i][j] == '1'){
					k++;
					ans = min(ans, prdz[i][j]);
					//if (ans == 1 && k<=3)cout << i << " " << j << " " << praj[i][j] << " " << k << endl;
					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 << pr[i] << endl;
	}
	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 26488 KB Output is correct
4 Correct 23 ms 26616 KB Output is correct
5 Correct 2 ms 420 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 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 888 KB Output is correct
19 Correct 2 ms 1016 KB Output is correct
20 Correct 3 ms 1016 KB Output is correct
21 Correct 2 ms 632 KB Output is correct
22 Correct 2 ms 888 KB Output is correct
23 Correct 2 ms 1016 KB Output is correct
24 Correct 2 ms 1020 KB Output is correct
25 Correct 3 ms 1400 KB Output is correct
26 Correct 3 ms 1528 KB Output is correct
27 Correct 6 ms 4088 KB Output is correct
28 Correct 3 ms 1528 KB Output is correct
29 Correct 8 ms 5288 KB Output is correct
30 Correct 7 ms 4344 KB Output is correct
31 Correct 5 ms 3192 KB Output is correct
32 Correct 6 ms 4216 KB Output is correct
33 Correct 8 ms 5368 KB Output is correct
34 Correct 3 ms 1784 KB Output is correct
35 Correct 4 ms 2168 KB Output is correct
36 Correct 8 ms 6852 KB Output is correct
37 Correct 2 ms 504 KB Output is correct
38 Correct 150 ms 58148 KB Output is correct
39 Correct 2 ms 504 KB Output is correct
40 Incorrect 23 ms 16248 KB Output isn't correct
41 Correct 2 ms 632 KB Output is correct
42 Correct 3 ms 1400 KB Output is correct
43 Correct 206 ms 54776 KB Output is correct
44 Correct 10 ms 6268 KB Output is correct
45 Correct 159 ms 56056 KB Output is correct
46 Correct 156 ms 58656 KB Output is correct
47 Correct 161 ms 56060 KB Output is correct
48 Correct 142 ms 58676 KB Output is correct
49 Correct 144 ms 58652 KB Output is correct
50 Correct 131 ms 58520 KB Output is correct
51 Correct 157 ms 58556 KB Output is correct
52 Correct 154 ms 58716 KB Output is correct
53 Correct 161 ms 57848 KB Output is correct
54 Correct 141 ms 45816 KB Output is correct
55 Correct 129 ms 44064 KB Output is correct
56 Correct 156 ms 59208 KB Output is correct
57 Correct 122 ms 39288 KB Output is correct
58 Correct 126 ms 44280 KB Output is correct
59 Correct 128 ms 41212 KB Output is correct
60 Correct 173 ms 51112 KB Output is correct
61 Correct 158 ms 59704 KB Output is correct
62 Correct 142 ms 59856 KB Output is correct
63 Correct 164 ms 59640 KB Output is correct
64 Correct 129 ms 42616 KB Output is correct
65 Correct 152 ms 58572 KB Output is correct
66 Correct 142 ms 55672 KB Output is correct
67 Correct 163 ms 60228 KB Output is correct
68 Correct 159 ms 60156 KB Output is correct
69 Correct 123 ms 39544 KB Output is correct
70 Correct 50 ms 18296 KB Output is correct
71 Correct 105 ms 29944 KB Output is correct
72 Correct 123 ms 33528 KB Output is correct
73 Correct 110 ms 34244 KB Output is correct
74 Correct 119 ms 39800 KB Output is correct
75 Correct 120 ms 41592 KB Output is correct
76 Correct 123 ms 42872 KB Output is correct
77 Correct 126 ms 43128 KB Output is correct
78 Correct 117 ms 43384 KB Output is correct
79 Correct 89 ms 16468 KB Output is correct
80 Correct 92 ms 17912 KB Output is correct
81 Correct 95 ms 18168 KB Output is correct
82 Correct 127 ms 46840 KB Output is correct
83 Correct 135 ms 46716 KB Output is correct
84 Correct 87 ms 11896 KB Output is correct
85 Correct 124 ms 45688 KB Output is correct
86 Correct 156 ms 59640 KB Output is correct
87 Correct 124 ms 45104 KB Output is correct
88 Correct 136 ms 46072 KB Output is correct
89 Correct 138 ms 54896 KB Output is correct
90 Correct 64 ms 33272 KB Output is correct
91 Correct 129 ms 50204 KB Output is correct
92 Correct 134 ms 51996 KB Output is correct
93 Correct 157 ms 59256 KB Output is correct
94 Correct 137 ms 53516 KB Output is correct
95 Correct 127 ms 47392 KB Output is correct
96 Correct 106 ms 46968 KB Output is correct
97 Correct 139 ms 59688 KB Output is correct
98 Correct 112 ms 47224 KB Output is correct
99 Correct 136 ms 53468 KB Output is correct
100 Correct 154 ms 58960 KB Output is correct