Submission #697232

# Submission time Handle Problem Language Result Execution time Memory
697232 2023-02-09T00:10:47 Z allllekssssa Bomb (IZhO17_bomb) C++14
26 / 100
467 ms 76752 KB
#include<bits/stdc++.h>
 
using namespace std;
 
const int maxN = 2600;
int n, m;
int a[maxN][maxN];
int d[maxN][maxN];
int c[maxN][maxN];
string s;
 
int getDSum(int x1, int y1, int x2, int y2) {
	if (x2 > n || y2 > m) return 0;
	return d[x2][y2] + d[x1 - 1][y1 - 1] - d[x1 - 1][y2] - d[x2][y1 - 1];
}
 
int getCSum(int x1, int y1, int x2, int y2) {
	x1 = max(x1, 1);
	y1 = max(y1, 1);
	return c[x2][y2] + c[x1 - 1][y1 - 1] - c[x1 - 1][y2] - c[x2][y1 - 1];
}
 
bool check(int x, int y) {
 
	for (int i = 1; i<=n; i++) {
		for (int j = 1; j<=m; j++) {
			c[i][j] = 0;
		}
	}
   
   for (int i = 1; i<=n; i++) {
   	 for (int j = 1; j<=m; j++) {
   	 	if (getDSum(i, j, i + x - 1, j + y - 1) == x * y) c[i][j] = 1;
   	 }
   }
 
   for (int i = 1; i <= n; i++) {
		for (int j = 1; j<=m; j++) {
			c[i][j] += c[i - 1][j] + c[i][j - 1] - c[i - 1][j - 1];
		}
	}
 
   for (int i = 1; i<=n; i++) {
   	for (int j = 1; j <= m; j++) {
 		  if (a[i][j] && getCSum(i - x + 1, j - y + 1, i, j) == 0) return false;
   	  }
   }
 
   return true;
}
 
int heuristic() {
  
   int minW = n;
   int minH = m;

	for (int i = 1; i<=n; i++) {
		int cur = 0;
		for (int j = 1; j<=m; j++) {
			if (a[i][j] == 1) cur++; else {
				if (cur > 0) {
					minH = min(minH, cur);
					cur = 0;
				}
			}
		}

	   if (cur > 0) minH = min(minH, cur);
	}

	for (int j = 1; j<=m; j++) {
		int cur = 0;
		for (int i = 1; i<=n; i++) {
			if (a[i][j] == 1) cur++; else {
				if (cur > 0) {
					minW = min(minW, cur);
					cur = 0;
				}
			}
		}

		if (cur > 0) minW = min(minW, cur);
	}
    
    int ans = 0;
	for (int i = 0; i< min(2, minW); i++) {
		for (int j = 0; j<min(2, minH); j++) {
           if (check(minW - i, minH -j)) ans = max(ans, (minW - i) * (minH -j));
		}
	}
	return ans;
}

int main() {
 
	cin >> n >> m;
 
	for (int i = 1; i <=n; i++) {
		cin >> s;
 
		for (int j = 0; j < m; j++) {
			a[i][j + 1] = s[j] - '0';
		}
	}
    
    for (int i = 1; i <= n; i++) {
		for (int j = 1; j<=m; j++) {
			d[i][j] = d[i - 1][j] + d[i][j - 1] + a[i][j] - d[i - 1][j - 1];
		}
	}

	if (n >= 2 || m >= 2) {
		cout << heuristic() << endl;
		return 0;
	}

   
    int ans = 0;
    
    int width = m;
	for (int i = 1; i <=n; i++) {
 
		while (width > 0 && !check(i, width)) width--;
 
		ans = max(ans, i * width);
	}
    
    cout << ans << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 15 ms 30420 KB Output is correct
4 Correct 13 ms 30420 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Incorrect 1 ms 468 KB Output isn't correct
9 Incorrect 1 ms 468 KB Output isn't correct
10 Correct 0 ms 468 KB Output is correct
11 Incorrect 0 ms 468 KB Output isn't correct
12 Correct 0 ms 468 KB Output is correct
13 Correct 0 ms 468 KB Output is correct
14 Correct 0 ms 468 KB Output is correct
15 Incorrect 0 ms 468 KB Output isn't correct
16 Correct 0 ms 468 KB Output is correct
17 Correct 1 ms 1108 KB Output is correct
18 Incorrect 1 ms 1108 KB Output isn't correct
19 Incorrect 1 ms 1492 KB Output isn't correct
20 Incorrect 1 ms 1492 KB Output isn't correct
21 Incorrect 1 ms 980 KB Output isn't correct
22 Incorrect 1 ms 1236 KB Output isn't correct
23 Incorrect 1 ms 1620 KB Output isn't correct
24 Incorrect 1 ms 1364 KB Output isn't correct
25 Incorrect 1 ms 1620 KB Output isn't correct
26 Correct 1 ms 1620 KB Output is correct
27 Correct 6 ms 4692 KB Output is correct
28 Incorrect 9 ms 5020 KB Output isn't correct
29 Incorrect 9 ms 6356 KB Output isn't correct
30 Incorrect 13 ms 7612 KB Output isn't correct
31 Incorrect 11 ms 5972 KB Output isn't correct
32 Incorrect 13 ms 6996 KB Output isn't correct
33 Incorrect 14 ms 7988 KB Output isn't correct
34 Incorrect 7 ms 5528 KB Output isn't correct
35 Incorrect 15 ms 8020 KB Output isn't correct
36 Correct 16 ms 8020 KB Output is correct
37 Incorrect 0 ms 468 KB Output isn't correct
38 Correct 455 ms 76632 KB Output is correct
39 Incorrect 1 ms 468 KB Output isn't correct
40 Incorrect 51 ms 19868 KB Output isn't correct
41 Incorrect 0 ms 468 KB Output isn't correct
42 Incorrect 1 ms 1620 KB Output isn't correct
43 Correct 467 ms 76624 KB Output is correct
44 Incorrect 13 ms 8020 KB Output isn't correct
45 Incorrect 372 ms 76744 KB Output isn't correct
46 Correct 429 ms 76628 KB Output is correct
47 Incorrect 360 ms 76748 KB Output isn't correct
48 Incorrect 376 ms 76604 KB Output isn't correct
49 Correct 447 ms 76624 KB Output is correct
50 Incorrect 372 ms 76556 KB Output isn't correct
51 Incorrect 376 ms 76628 KB Output isn't correct
52 Incorrect 369 ms 76628 KB Output isn't correct
53 Incorrect 371 ms 76628 KB Output isn't correct
54 Incorrect 371 ms 76628 KB Output isn't correct
55 Incorrect 372 ms 76636 KB Output isn't correct
56 Correct 435 ms 76620 KB Output is correct
57 Incorrect 397 ms 76632 KB Output isn't correct
58 Incorrect 403 ms 76632 KB Output isn't correct
59 Incorrect 399 ms 76628 KB Output isn't correct
60 Correct 415 ms 76628 KB Output is correct
61 Correct 458 ms 76536 KB Output is correct
62 Correct 441 ms 76536 KB Output is correct
63 Correct 440 ms 76732 KB Output is correct
64 Correct 404 ms 76632 KB Output is correct
65 Incorrect 371 ms 76616 KB Output isn't correct
66 Incorrect 393 ms 76628 KB Output isn't correct
67 Incorrect 367 ms 76692 KB Output isn't correct
68 Incorrect 362 ms 76704 KB Output isn't correct
69 Incorrect 411 ms 76600 KB Output isn't correct
70 Incorrect 236 ms 61332 KB Output isn't correct
71 Incorrect 381 ms 76656 KB Output isn't correct
72 Incorrect 367 ms 76604 KB Output isn't correct
73 Incorrect 382 ms 76628 KB Output isn't correct
74 Incorrect 380 ms 76628 KB Output isn't correct
75 Incorrect 365 ms 76628 KB Output isn't correct
76 Incorrect 366 ms 76528 KB Output isn't correct
77 Incorrect 369 ms 76548 KB Output isn't correct
78 Incorrect 368 ms 76628 KB Output isn't correct
79 Incorrect 367 ms 76752 KB Output isn't correct
80 Incorrect 364 ms 76680 KB Output isn't correct
81 Incorrect 369 ms 76628 KB Output isn't correct
82 Incorrect 374 ms 76624 KB Output isn't correct
83 Incorrect 378 ms 76632 KB Output isn't correct
84 Incorrect 387 ms 76664 KB Output isn't correct
85 Incorrect 372 ms 76628 KB Output isn't correct
86 Incorrect 377 ms 76668 KB Output isn't correct
87 Incorrect 366 ms 76628 KB Output isn't correct
88 Incorrect 374 ms 76548 KB Output isn't correct
89 Incorrect 367 ms 76628 KB Output isn't correct
90 Incorrect 252 ms 61356 KB Output isn't correct
91 Incorrect 371 ms 76624 KB Output isn't correct
92 Incorrect 376 ms 76624 KB Output isn't correct
93 Incorrect 365 ms 76624 KB Output isn't correct
94 Incorrect 371 ms 76628 KB Output isn't correct
95 Incorrect 378 ms 76544 KB Output isn't correct
96 Incorrect 362 ms 76652 KB Output isn't correct
97 Incorrect 367 ms 76548 KB Output isn't correct
98 Incorrect 368 ms 76560 KB Output isn't correct
99 Incorrect 407 ms 76672 KB Output isn't correct
100 Incorrect 366 ms 76632 KB Output isn't correct