Submission #93212

# Submission time Handle Problem Language Result Execution time Memory
93212 2019-01-07T09:44:56 Z Abelyan Bomb (IZhO17_bomb) C++17
90 / 100
209 ms 56184 KB
#include <iostream>
#include <algorithm>
#include <climits>
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)return;
	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;
	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<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++;
			}
		}
	}
	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
*/
# Verdict Execution time Memory 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 23 ms 26488 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 504 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 Incorrect 2 ms 1016 KB Output isn't correct
18 Correct 2 ms 888 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 3 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 3 ms 1528 KB Output isn't correct
27 Correct 6 ms 4088 KB Output is correct
28 Correct 3 ms 1528 KB Output is correct
29 Incorrect 8 ms 5368 KB Output isn't 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 5496 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 6908 KB Output isn't correct
37 Correct 2 ms 632 KB Output is correct
38 Correct 157 ms 56028 KB Output is correct
39 Correct 2 ms 632 KB Output is correct
40 Incorrect 25 ms 15736 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 209 ms 52220 KB Output is correct
44 Correct 9 ms 6264 KB Output is correct
45 Correct 169 ms 53600 KB Output is correct
46 Correct 159 ms 56056 KB Output is correct
47 Correct 174 ms 53624 KB Output is correct
48 Incorrect 153 ms 56144 KB Output isn't correct
49 Correct 189 ms 56184 KB Output is correct
50 Incorrect 161 ms 56056 KB Output isn't correct
51 Incorrect 158 ms 56028 KB Output isn't correct
52 Correct 151 ms 56028 KB Output is correct
53 Correct 157 ms 55416 KB Output is correct
54 Correct 105 ms 42744 KB Output is correct
55 Correct 101 ms 41080 KB Output is correct
56 Correct 168 ms 56056 KB Output is correct
57 Correct 112 ms 36292 KB Output is correct
58 Correct 101 ms 41080 KB Output is correct
59 Correct 120 ms 38012 KB Output is correct
60 Correct 170 ms 47992 KB Output is correct
61 Correct 178 ms 56092 KB Output is correct
62 Correct 165 ms 56056 KB Output is correct
63 Correct 139 ms 56056 KB Output is correct
64 Correct 108 ms 38864 KB Output is correct
65 Correct 134 ms 54904 KB Output is correct
66 Correct 117 ms 51320 KB Output is correct
67 Incorrect 144 ms 55492 KB Output isn't correct
68 Incorrect 160 ms 55512 KB Output isn't correct
69 Correct 95 ms 35164 KB Output is correct
70 Correct 54 ms 15224 KB Output is correct
71 Correct 95 ms 28180 KB Output is correct
72 Correct 95 ms 33656 KB Output is correct
73 Correct 101 ms 34116 KB Output is correct
74 Correct 114 ms 35704 KB Output is correct
75 Correct 115 ms 37240 KB Output is correct
76 Correct 118 ms 38648 KB Output is correct
77 Correct 129 ms 39160 KB Output is correct
78 Correct 95 ms 39376 KB Output is correct
79 Correct 96 ms 11768 KB Output is correct
80 Correct 64 ms 13048 KB Output is correct
81 Correct 69 ms 13432 KB Output is correct
82 Correct 106 ms 41772 KB Output is correct
83 Correct 99 ms 41976 KB Output is correct
84 Correct 54 ms 7032 KB Output is correct
85 Correct 123 ms 40952 KB Output is correct
86 Correct 152 ms 54392 KB Output is correct
87 Correct 121 ms 39800 KB Output is correct
88 Correct 105 ms 40712 KB Output is correct
89 Correct 115 ms 49424 KB Output is correct
90 Correct 62 ms 29576 KB Output is correct
91 Correct 105 ms 44672 KB Output is correct
92 Correct 131 ms 46344 KB Output is correct
93 Correct 135 ms 53588 KB Output is correct
94 Correct 117 ms 48180 KB Output is correct
95 Correct 104 ms 42048 KB Output is correct
96 Correct 131 ms 41612 KB Output is correct
97 Correct 157 ms 54236 KB Output is correct
98 Correct 126 ms 41592 KB Output is correct
99 Correct 135 ms 47836 KB Output is correct
100 Correct 147 ms 52996 KB Output is correct