Submission #93238

#TimeUsernameProblemLanguageResultExecution timeMemory
93238VardanyanBomb (IZhO17_bomb)C++11
99 / 100
280 ms87996 KiB
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <bitset>
#include <cstring>
#include <vector>
using namespace std;
const int N = 2505;
int dzaxic[N][N];
int ajic[N][N];
int a[N][N];
int n, m;
int M[N];

int mnw = 1000 * 1000 * 1000 + 5;
int mnh = mnw;
vector<pair<int, int> > v;
int main(){
	ios_base::sync_with_stdio(false);
	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++)
	{
		int now = 0;
		for (int j = 1; j <= m; j++){
			if (a[i][j]){
				now++;
				dzaxic[i][j] = now;
			}
			else{
				if (now)	mnw = min(mnw, now);
				now = 0;
			}
		}
		if (now)	mnw = min(mnw, now);
		now = 0;
		for (int j = m; j >= 1; j--){
			if (a[i][j]){
				now++;
				ajic[i][j] = now;
			}
			else{
				if (now)	mnw = min(mnw, now);
				now = 0;
			}
		}
		if (now)	mnw = min(mnw, now);
		now = 0;
	}
	for (int j = 1; j <= m; j++){
		int now = 0;
		for (int i = 1; i <= n; i++){
			if (a[i][j]){
				now++;
			}
			else{
				if (now)	mnh = min(mnh, now);
				now = 0;
			}
		}
		if (now)	mnh = min(mnh, now);
	}
	//cout << mnh << " " << mnw << endl;
	/*for (int i = 1; i <= n; i++){
	for (int j = 1; j <= m; j++){
	cout <<ajic[i][j] << " ";
	}
	cout << endl;
	}*/
	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= m; j++){
			/*if (i == 9 && j == 10){
				cout << 0 << endl;
			}*/
			if (a[i][j] == 1 && a[i - 1][j] == 0 && a[i][j - 1] == 0 && a[i - 1][j - 1] == 0){
				int now = -1;
				//calc1(i, j, 1);
				for (int ii = i; ii <= n; ii++){
					if (a[ii][j] == 0) break;
					if (now == -1 || ajic[ii][j] < now){
						now = ajic[ii][j];
					}
					now = min(now, mnw);
					v.push_back({ ii - i + 1, now });
					if (ii - i + 1 >= mnh) break;
				}
			}
			if (a[i][j] == 1 && a[i][j - 1] == 0 && a[i + 1][j - 1] == 0 && a[i+1][j] == 0){
				int now = -1;
				//calc1(i, j, -1);
				for (int ii = i; ii >= 1; ii--){
					if (a[ii][j] == 0) break;
					if (now == -1 || ajic[ii][j] < now){
						now = ajic[ii][j];
					}
					now = min(now, mnw);
					v.push_back({ i - ii + 1, now });
					if (i - ii + 1 >= mnh) break;
				}
			}
			if (a[i][j] == 1 && a[i - 1][j] == 0 && a[i][j + 1] == 0 && a[i - 1][j + 1] == 0){
				int now = -1;
				for (int ii = i; ii <= n; ii++){
					if (a[ii][j] == 0) break;
					if (now == -1 || dzaxic[ii][j] < now){
						now = dzaxic[ii][j];
					}
					now = min(now, mnw);
					v.push_back({ ii - i + 1, now });
					if (ii - i + 1 >= mnh) break;
				}
			}
			if (a[i][j] == 1 && a[i + 1][j] == 0 && a[i][j + 1] == 0 && a[i + 1][j + 1] == 0){
				int now = -1;
				for (int ii = i; ii >= 1; ii--){
					if (a[ii][j] == 0) break;
					if (now == -1 || dzaxic[ii][j] < now){
						now = dzaxic[ii][j];
					}
					now = min(now, mnw);
					v.push_back({ i - ii + 1, now });
					if (i - ii + 1 >= mnh) break;
				}
			}
		}
	}
	//	cout << mnh << " " << mnw << endl;
	memset(M, -1, sizeof M);
	for (int i = 0; i < v.size(); i++){
		int a = v[i].first;
		int b = v[i].second;
		b = min(b, mnw);
		if (M[a] == -1 || M[a] > b){
			M[a] = b;
		}
		//cout << a << " " << b << endl;
	}
	int ans = 0;
	for (int i = 0; i < v.size(); i++){
		int a = v[i].first;
		//a = min(a, mnh);
		//if (a > mnh) continue;
		int b = M[a];
		a *= b;
		ans = max(ans, a);
	}
	cout << ans << endl;
	return 0;
}

Compilation message (stderr)

bomb.cpp: In function 'int main()':
bomb.cpp:135:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < v.size(); i++){
                  ~~^~~~~~~~~~
bomb.cpp:145:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < v.size(); i++){
                  ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...