Submission #109219

#TimeUsernameProblemLanguageResultExecution timeMemory
109219ihdigniteBomb (IZhO17_bomb)C++14
100 / 100
494 ms62328 KiB
#include <bits/stdc++.h>
using namespace std;

const int mxN=2500;
int n, m, mxw=mxN, mxh=mxN, u[mxN][mxN], d[mxN][mxN], a[mxN], ans;
string g[mxN];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	cin >> n >> m;
	for(int i=0; i<n; ++i) {
		cin >> g[i];
		for(int j=0, w=0; j<m; ++j) {
			w=g[i][j]&1?w+1:0;
			if(w&&(j+1>=m||g[i][j+1]&1^1))
				mxw=min(w, mxw);
		}
	}
	for(int j=0; j<m; ++j) {
		for(int i=0, h=0; i<n; ++i) {
			h=g[i][j]&1?h+1:0;
			if(h&&(i+1>=n||g[i+1][j]&1^1))
				mxh=min(h, mxh);
			u[i][j]=i&&g[i-1][j]&1?u[i-1][j]:i;
		}
		for(int i=n-1; ~i; --i)
			d[i][j]=i<n-1&&g[i+1][j]&1?d[i+1][j]:i;
	}
	for(int i=0; i<mxw; ++i)
		a[i]=mxh;
	auto c=[]() {
		for(int i=0; i<n; ++i) {
			for(int j=0; j<m; ++j) {
				if(j&&g[i][j-1]&1||g[i][j]&1^1)
					continue;
				for(int k=0, l=0, r=n; k<mxw; ++k) {
					l=max(u[i][j+k], l);
					r=min(d[i][j+k], r);
					a[k]=min(r-l+1, a[k]);
				}
			}
		}
	};
	c();
	for(int i=0; i<n; ++i) {
		reverse(g[i].begin(), g[i].end());
		reverse(u[i], u[i]+m);
		reverse(d[i], d[i]+m);
	}
	c();
	for(int i=0; i<mxw; ++i)
		ans=max((i+1)*a[i], ans);
	cout << ans;
}

Compilation message (stderr)

bomb.cpp: In function 'int main()':
bomb.cpp:17:28: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
    if(w&&(j+1>=m||g[i][j+1]&1^1))
bomb.cpp:24:28: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
    if(h&&(i+1>=n||g[i+1][j]&1^1))
bomb.cpp: In lambda function:
bomb.cpp:36:31: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
     if(j&&g[i][j-1]&1||g[i][j]&1^1)
bomb.cpp:36:9: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
     if(j&&g[i][j-1]&1||g[i][j]&1^1)
        ~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...