Submission #1102962

#TimeUsernameProblemLanguageResultExecution timeMemory
1102962MuhammetBomb (IZhO17_bomb)C++17
24 / 100
360 ms105832 KiB
#include <bits/stdc++.h>

using namespace std;

const int N = 2505;

int n, m, a[N][N], b[N][N], c[N][N], d[N][N];

char e[N][N];

int main(){
	cin >> n >> m;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			cin >> e[i][j];
		}
	}
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			if(e[i][j] == '1'){
				a[i][j] = a[i][j-1] + 1;
			}
			else {
				a[i][j] = 0;
			}
		}
	}
	for(int i = 1; i <= n; i++){
		for(int j = m; j >= 1; j--){
			if(e[i][j] == '1'){
				b[i][j] = b[i][j+1] + 1;
			}
			else {
				b[i][j] = 0;
			}
		}
	}
	for(int j = 1; j <= m; j++){
		for(int i = 1; i <= n; i++){
			if(e[i][j] == '1'){
				c[i][j] = c[i-1][j] + 1;
			}
			else {
				c[i][j] = 0;
			}
		}
	}
	for(int j = 1; j <= m; j++){
		for(int i = n; i >= 1; i--){
			if(e[i][j] == '1'){
				d[i][j] = d[i+1][j] + 1;
			}
			else {
				d[i][j] = 0;
			}
		}
	}
	int n1 = 1e9, m1 = 1e9;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			if(e[i][j] == '0') continue;
			n1 = min(n1, (c[i][j] + d[i][j]) - 1);
			m1 = min(m1, (a[i][j] + b[i][j]) - 1);
		}
	}
	if(n1 == 1e9 and m1 == 1e9) cout << 0;
	else cout << n1*m1;
}
#Verdict Execution timeMemoryGrader output
Fetching results...