Submission #334580

# Submission time Handle Problem Language Result Execution time Memory
334580 2020-12-09T13:06:01 Z amunduzbaev Bomb (IZhO17_bomb) C++14
86 / 100
240 ms 131076 KB
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define ll long long 
#define ld long double 
#define pii pair<int, int>
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(),x.rend()
#define prc(n) fixed << setprecision(n)
#define fastios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pi acos(-1);
const int inf = 1e9+7;
const int N = 2505;
ll a[N][N], mnc, mnr, d[N][N], u[N][N], ans[N];

void solve(){
	mnr = inf, mnc = inf;
	int n, m;
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			char c;
			cin>>c;
			a[i][j] = c - '0';
		}
	}
	
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(a[i][j])u[i][j] = u[i-1][j] + 1;
		}
	}

	for(int i=n;i>0;i--){
		for(int j=1;j<=m;j++){
			if(a[i][j]){
				d[i][j] = d[i+1][j]+1;
				if(a[i+1][j] == 0) mnc = min(mnc, u[i][j]);
			}
		}
	}
	
	
	for(int i=1;i<=m;i++) ans[i] = mnc;
	
	for(int i=1;i<=n;i++){
		ll aa = inf, b = inf, c = 0;
		for(int j=1;j<=m;j++){
			if(a[i][j] == 0){
				if(c!=0) mnc = min(c, mnc);
				aa = b = inf, c = 0;
			}else{
				aa = min(aa, d[i][j]);
				b = min(b, u[i][j]);
				c++;
				ans[c] = min(ans[c], b + aa -1);
			}
		}
		
		aa = inf, b = inf, c = 0;
		for(int j = m; j>0; j--){
			if(a[i][j] == 0){
				if(c!=0) mnr = min(mnr, c);
				aa = b = inf, c = 0;
			}else{
				aa = min(d[i][j], aa);
				b = min(u[i][j], b);
				c++;
				ans[c] = min(ans[c], b + aa -1);
			}
		}
		if(c > 0) mnr = min(mnr, c);
	}
	ll mx = 0;
	for(int i=1;i<=mnr;i++){
		mx = max((ll)ans[i] * (ll)i, mx);
	}
	cout<<mx<<"\n";
	return;
}

 
int main(){
	fastios
	int t = 1;
	//cin>>t;
	while(t--) solve();
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 16 ms 30572 KB Output is correct
4 Correct 16 ms 30572 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 640 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 620 KB Output is correct
12 Correct 1 ms 636 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 620 KB Output is correct
17 Correct 1 ms 1164 KB Output is correct
18 Correct 1 ms 924 KB Output is correct
19 Correct 1 ms 1260 KB Output is correct
20 Correct 1 ms 1260 KB Output is correct
21 Correct 1 ms 768 KB Output is correct
22 Correct 1 ms 1004 KB Output is correct
23 Correct 1 ms 1388 KB Output is correct
24 Correct 1 ms 1260 KB Output is correct
25 Correct 2 ms 1644 KB Output is correct
26 Correct 2 ms 1772 KB Output is correct
27 Correct 6 ms 5868 KB Output is correct
28 Correct 4 ms 2924 KB Output is correct
29 Correct 7 ms 7660 KB Output is correct
30 Correct 10 ms 6892 KB Output is correct
31 Correct 7 ms 5100 KB Output is correct
32 Correct 7 ms 6252 KB Output is correct
33 Correct 9 ms 8172 KB Output is correct
34 Correct 4 ms 3052 KB Output is correct
35 Correct 7 ms 4588 KB Output is correct
36 Correct 10 ms 10732 KB Output is correct
37 Correct 1 ms 620 KB Output is correct
38 Runtime error 179 ms 131076 KB Execution killed with signal 9 (could be triggered by violating memory limits)
39 Correct 1 ms 620 KB Output is correct
40 Correct 40 ms 29824 KB Output is correct
41 Correct 1 ms 620 KB Output is correct
42 Correct 2 ms 1772 KB Output is correct
43 Correct 200 ms 131072 KB Output is correct
44 Correct 10 ms 9580 KB Output is correct
45 Correct 198 ms 130156 KB Output is correct
46 Runtime error 185 ms 131076 KB Execution killed with signal 9 (could be triggered by violating memory limits)
47 Correct 239 ms 130284 KB Output is correct
48 Correct 202 ms 131072 KB Output is correct
49 Runtime error 175 ms 131076 KB Execution killed with signal 9 (could be triggered by violating memory limits)
50 Runtime error 177 ms 131076 KB Execution killed with signal 9 (could be triggered by violating memory limits)
51 Correct 202 ms 131052 KB Output is correct
52 Correct 240 ms 131072 KB Output is correct
53 Correct 197 ms 128236 KB Output is correct
54 Correct 198 ms 108164 KB Output is correct
55 Correct 188 ms 104484 KB Output is correct
56 Runtime error 193 ms 131076 KB Execution killed with signal 9 (could be triggered by violating memory limits)
57 Correct 181 ms 93292 KB Output is correct
58 Correct 187 ms 99436 KB Output is correct
59 Correct 195 ms 95340 KB Output is correct
60 Correct 195 ms 119148 KB Output is correct
61 Runtime error 174 ms 131072 KB Execution killed with signal 9 (could be triggered by violating memory limits)
62 Runtime error 176 ms 131076 KB Execution killed with signal 9 (could be triggered by violating memory limits)
63 Runtime error 176 ms 131076 KB Execution killed with signal 9 (could be triggered by violating memory limits)
64 Correct 230 ms 96740 KB Output is correct
65 Correct 210 ms 126956 KB Output is correct
66 Correct 197 ms 122348 KB Output is correct
67 Runtime error 179 ms 131076 KB Execution killed with signal 9 (could be triggered by violating memory limits)
68 Runtime error 179 ms 131076 KB Execution killed with signal 9 (could be triggered by violating memory limits)
69 Correct 180 ms 93036 KB Output is correct
70 Correct 112 ms 54636 KB Output is correct
71 Correct 172 ms 80608 KB Output is correct
72 Correct 176 ms 90732 KB Output is correct
73 Correct 182 ms 92928 KB Output is correct
74 Correct 186 ms 93164 KB Output is correct
75 Correct 179 ms 95596 KB Output is correct
76 Correct 178 ms 97772 KB Output is correct
77 Correct 184 ms 99180 KB Output is correct
78 Correct 179 ms 99116 KB Output is correct
79 Correct 159 ms 56556 KB Output is correct
80 Correct 159 ms 57836 KB Output is correct
81 Correct 160 ms 59628 KB Output is correct
82 Correct 185 ms 102636 KB Output is correct
83 Correct 183 ms 102764 KB Output is correct
84 Correct 155 ms 51820 KB Output is correct
85 Correct 181 ms 99820 KB Output is correct
86 Runtime error 176 ms 131076 KB Execution killed with signal 9 (could be triggered by violating memory limits)
87 Correct 180 ms 97656 KB Output is correct
88 Correct 183 ms 101472 KB Output is correct
89 Correct 191 ms 118224 KB Output is correct
90 Correct 126 ms 73708 KB Output is correct
91 Correct 183 ms 107372 KB Output is correct
92 Correct 194 ms 118484 KB Output is correct
93 Runtime error 171 ms 131072 KB Execution killed with signal 9 (could be triggered by violating memory limits)
94 Correct 192 ms 118380 KB Output is correct
95 Correct 182 ms 102784 KB Output is correct
96 Correct 181 ms 102380 KB Output is correct
97 Runtime error 174 ms 131076 KB Execution killed with signal 9 (could be triggered by violating memory limits)
98 Correct 181 ms 102380 KB Output is correct
99 Correct 188 ms 116864 KB Output is correct
100 Runtime error 182 ms 131076 KB Execution killed with signal 9 (could be triggered by violating memory limits)