# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
697228 |
2023-02-09T00:05:51 Z |
allllekssssa |
Bomb (IZhO17_bomb) |
C++14 |
|
1000 ms |
54768 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<minW; i++) {
for (int j = 0; j<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';
}
}
if (n >= 500 || m >= 500) {
cout << heuristic() << endl;
return 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];
}
}
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 |
Incorrect |
10 ms |
20436 KB |
Output isn't correct |
4 |
Incorrect |
11 ms |
20408 KB |
Output isn't correct |
5 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
6 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
560 KB |
Output is correct |
12 |
Correct |
1 ms |
432 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
3 ms |
1164 KB |
Output is correct |
18 |
Correct |
3 ms |
1108 KB |
Output is correct |
19 |
Correct |
5 ms |
1536 KB |
Output is correct |
20 |
Correct |
9 ms |
1524 KB |
Output is correct |
21 |
Correct |
4 ms |
952 KB |
Output is correct |
22 |
Correct |
6 ms |
1320 KB |
Output is correct |
23 |
Correct |
9 ms |
1620 KB |
Output is correct |
24 |
Correct |
5 ms |
1336 KB |
Output is correct |
25 |
Correct |
11 ms |
1644 KB |
Output is correct |
26 |
Correct |
8 ms |
1620 KB |
Output is correct |
27 |
Correct |
127 ms |
4856 KB |
Output is correct |
28 |
Correct |
249 ms |
5180 KB |
Output is correct |
29 |
Correct |
322 ms |
6572 KB |
Output is correct |
30 |
Correct |
631 ms |
7872 KB |
Output is correct |
31 |
Correct |
482 ms |
6228 KB |
Output is correct |
32 |
Correct |
481 ms |
7144 KB |
Output is correct |
33 |
Correct |
767 ms |
8280 KB |
Output is correct |
34 |
Correct |
118 ms |
5600 KB |
Output is correct |
35 |
Correct |
581 ms |
8252 KB |
Output is correct |
36 |
Correct |
701 ms |
8288 KB |
Output is correct |
37 |
Correct |
1 ms |
468 KB |
Output is correct |
38 |
Execution timed out |
1006 ms |
53616 KB |
Time limit exceeded |
39 |
Correct |
1 ms |
468 KB |
Output is correct |
40 |
Execution timed out |
1088 ms |
14060 KB |
Time limit exceeded |
41 |
Correct |
1 ms |
468 KB |
Output is correct |
42 |
Correct |
12 ms |
1620 KB |
Output is correct |
43 |
Execution timed out |
1095 ms |
53728 KB |
Time limit exceeded |
44 |
Correct |
922 ms |
8304 KB |
Output is correct |
45 |
Execution timed out |
1014 ms |
53668 KB |
Time limit exceeded |
46 |
Execution timed out |
1024 ms |
53696 KB |
Time limit exceeded |
47 |
Execution timed out |
1027 ms |
53780 KB |
Time limit exceeded |
48 |
Execution timed out |
1097 ms |
53764 KB |
Time limit exceeded |
49 |
Execution timed out |
1064 ms |
53772 KB |
Time limit exceeded |
50 |
Execution timed out |
1030 ms |
53716 KB |
Time limit exceeded |
51 |
Execution timed out |
1042 ms |
53848 KB |
Time limit exceeded |
52 |
Execution timed out |
1010 ms |
53708 KB |
Time limit exceeded |
53 |
Execution timed out |
1081 ms |
53772 KB |
Time limit exceeded |
54 |
Execution timed out |
1014 ms |
53836 KB |
Time limit exceeded |
55 |
Execution timed out |
1093 ms |
53668 KB |
Time limit exceeded |
56 |
Execution timed out |
1016 ms |
53452 KB |
Time limit exceeded |
57 |
Execution timed out |
1028 ms |
53484 KB |
Time limit exceeded |
58 |
Execution timed out |
1022 ms |
53640 KB |
Time limit exceeded |
59 |
Execution timed out |
1018 ms |
53456 KB |
Time limit exceeded |
60 |
Execution timed out |
1012 ms |
53444 KB |
Time limit exceeded |
61 |
Execution timed out |
1022 ms |
53500 KB |
Time limit exceeded |
62 |
Execution timed out |
1010 ms |
53388 KB |
Time limit exceeded |
63 |
Execution timed out |
1020 ms |
53328 KB |
Time limit exceeded |
64 |
Execution timed out |
1033 ms |
53284 KB |
Time limit exceeded |
65 |
Execution timed out |
1043 ms |
53244 KB |
Time limit exceeded |
66 |
Execution timed out |
1040 ms |
53208 KB |
Time limit exceeded |
67 |
Execution timed out |
1030 ms |
54004 KB |
Time limit exceeded |
68 |
Execution timed out |
1022 ms |
54504 KB |
Time limit exceeded |
69 |
Execution timed out |
1042 ms |
54404 KB |
Time limit exceeded |
70 |
Execution timed out |
1043 ms |
42620 KB |
Time limit exceeded |
71 |
Execution timed out |
1096 ms |
54320 KB |
Time limit exceeded |
72 |
Execution timed out |
1034 ms |
54400 KB |
Time limit exceeded |
73 |
Execution timed out |
1033 ms |
54392 KB |
Time limit exceeded |
74 |
Execution timed out |
1104 ms |
54384 KB |
Time limit exceeded |
75 |
Execution timed out |
1049 ms |
54424 KB |
Time limit exceeded |
76 |
Execution timed out |
1020 ms |
54416 KB |
Time limit exceeded |
77 |
Execution timed out |
1082 ms |
54444 KB |
Time limit exceeded |
78 |
Execution timed out |
1083 ms |
54356 KB |
Time limit exceeded |
79 |
Execution timed out |
1051 ms |
54240 KB |
Time limit exceeded |
80 |
Execution timed out |
1025 ms |
54236 KB |
Time limit exceeded |
81 |
Execution timed out |
1022 ms |
54272 KB |
Time limit exceeded |
82 |
Execution timed out |
1020 ms |
54228 KB |
Time limit exceeded |
83 |
Execution timed out |
1085 ms |
54296 KB |
Time limit exceeded |
84 |
Execution timed out |
1044 ms |
54300 KB |
Time limit exceeded |
85 |
Execution timed out |
1048 ms |
54276 KB |
Time limit exceeded |
86 |
Execution timed out |
1012 ms |
54304 KB |
Time limit exceeded |
87 |
Execution timed out |
1020 ms |
54292 KB |
Time limit exceeded |
88 |
Execution timed out |
1050 ms |
54220 KB |
Time limit exceeded |
89 |
Execution timed out |
1022 ms |
54276 KB |
Time limit exceeded |
90 |
Execution timed out |
1048 ms |
43120 KB |
Time limit exceeded |
91 |
Execution timed out |
1100 ms |
54768 KB |
Time limit exceeded |
92 |
Execution timed out |
1029 ms |
54544 KB |
Time limit exceeded |
93 |
Execution timed out |
1085 ms |
54548 KB |
Time limit exceeded |
94 |
Execution timed out |
1053 ms |
54556 KB |
Time limit exceeded |
95 |
Execution timed out |
1035 ms |
54556 KB |
Time limit exceeded |
96 |
Execution timed out |
1060 ms |
54536 KB |
Time limit exceeded |
97 |
Execution timed out |
1106 ms |
54452 KB |
Time limit exceeded |
98 |
Execution timed out |
1028 ms |
54476 KB |
Time limit exceeded |
99 |
Execution timed out |
1057 ms |
54608 KB |
Time limit exceeded |
100 |
Execution timed out |
1032 ms |
54540 KB |
Time limit exceeded |