Submission #93280

# Submission time Handle Problem Language Result Execution time Memory
93280 2019-01-07T11:59:01 Z Abelyan Bomb (IZhO17_bomb) C++17
100 / 100
476 ms 61688 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'){
				int ansaj = INT_MAX,ansdz=INT_MAX, k = 0;
				while (i<n && c[i][j] == '1'){
					k++;
					ansaj = min(ansaj, praj[i][j]);
                  	ansdz = min(ansdz, prdz[i][j]);
					//if (ans == 1 && k<=3)cout << i << " " << j << " " << praj[i][j] << " " << k << endl;
					ad(k, ansaj+ansdz-1);
					i++;
				}
				i--;
			}
		}
	}
	for (int j = 0; j<m; j++){
		for (int i = n - 1; i >= 0; i--){
			if (c[i][j] == '1'){
				int ansdz = INT_MAX,ansaj=INT_MAX, k = 0;
				while (i>=0 && c[i][j] == '1'){
					k++;
					ansaj = min(ansaj, praj[i][j]);
                  	ansdz = min(ansdz, prdz[i][j]);
					//if (ans == 1 && k<=3)cout << i << " " << j << " " << praj[i][j] << " " << k << endl;
					ad(k, ansaj+ansdz-1);
					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;
}
# 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 21 ms 26616 KB Output is correct
4 Correct 22 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 7 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 632 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 2 ms 1016 KB Output is correct
18 Correct 2 ms 760 KB Output is correct
19 Correct 2 ms 1020 KB Output is correct
20 Correct 2 ms 1016 KB Output is correct
21 Correct 2 ms 504 KB Output is correct
22 Correct 2 ms 888 KB Output is correct
23 Correct 2 ms 1144 KB Output is correct
24 Correct 2 ms 888 KB Output is correct
25 Correct 3 ms 1404 KB Output is correct
26 Correct 2 ms 1400 KB Output is correct
27 Correct 6 ms 4088 KB Output is correct
28 Correct 4 ms 1528 KB Output is correct
29 Correct 7 ms 5240 KB Output is correct
30 Correct 7 ms 4344 KB Output is correct
31 Correct 6 ms 3192 KB Output is correct
32 Correct 7 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 2176 KB Output is correct
36 Correct 9 ms 6776 KB Output is correct
37 Correct 2 ms 504 KB Output is correct
38 Correct 466 ms 61540 KB Output is correct
39 Correct 2 ms 636 KB Output is correct
40 Correct 51 ms 16248 KB Output is correct
41 Correct 2 ms 632 KB Output is correct
42 Correct 3 ms 1400 KB Output is correct
43 Correct 356 ms 57592 KB Output is correct
44 Correct 9 ms 6136 KB Output is correct
45 Correct 348 ms 59128 KB Output is correct
46 Correct 314 ms 61560 KB Output is correct
47 Correct 341 ms 59128 KB Output is correct
48 Correct 313 ms 61564 KB Output is correct
49 Correct 476 ms 61688 KB Output is correct
50 Correct 336 ms 61688 KB Output is correct
51 Correct 328 ms 61560 KB Output is correct
52 Correct 324 ms 61560 KB Output is correct
53 Correct 325 ms 60796 KB Output is correct
54 Correct 224 ms 47608 KB Output is correct
55 Correct 222 ms 46044 KB Output is correct
56 Correct 467 ms 60956 KB Output is correct
57 Correct 205 ms 40824 KB Output is correct
58 Correct 224 ms 45816 KB Output is correct
59 Correct 210 ms 42744 KB Output is correct
60 Correct 296 ms 52480 KB Output is correct
61 Correct 460 ms 60280 KB Output is correct
62 Correct 445 ms 60152 KB Output is correct
63 Correct 447 ms 60280 KB Output is correct
64 Correct 214 ms 43384 KB Output is correct
65 Correct 319 ms 59580 KB Output is correct
66 Correct 314 ms 56056 KB Output is correct
67 Correct 346 ms 60096 KB Output is correct
68 Correct 342 ms 60124 KB Output is correct
69 Correct 189 ms 39748 KB Output is correct
70 Correct 61 ms 18936 KB Output is correct
71 Correct 133 ms 30076 KB Output is correct
72 Correct 169 ms 33656 KB Output is correct
73 Correct 178 ms 34040 KB Output is correct
74 Correct 205 ms 39904 KB Output is correct
75 Correct 183 ms 41860 KB Output is correct
76 Correct 195 ms 43356 KB Output is correct
77 Correct 203 ms 43840 KB Output is correct
78 Correct 199 ms 44152 KB Output is correct
79 Correct 66 ms 16248 KB Output is correct
80 Correct 65 ms 17528 KB Output is correct
81 Correct 94 ms 18052 KB Output is correct
82 Correct 246 ms 46116 KB Output is correct
83 Correct 213 ms 46820 KB Output is correct
84 Correct 78 ms 11896 KB Output is correct
85 Correct 210 ms 45420 KB Output is correct
86 Correct 437 ms 58616 KB Output is correct
87 Correct 195 ms 44024 KB Output is correct
88 Correct 231 ms 44924 KB Output is correct
89 Correct 296 ms 53624 KB Output is correct
90 Correct 119 ms 33144 KB Output is correct
91 Correct 243 ms 48504 KB Output is correct
92 Correct 290 ms 50088 KB Output is correct
93 Correct 417 ms 57336 KB Output is correct
94 Correct 283 ms 52224 KB Output is correct
95 Correct 224 ms 46072 KB Output is correct
96 Correct 239 ms 45816 KB Output is correct
97 Correct 433 ms 58288 KB Output is correct
98 Correct 232 ms 45560 KB Output is correct
99 Correct 296 ms 51612 KB Output is correct
100 Correct 425 ms 56952 KB Output is correct