# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
697253 |
2023-02-09T01:20:56 Z |
allllekssssa |
Bomb (IZhO17_bomb) |
C++14 |
|
1000 ms |
78424 KB |
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int ,int>
#define pb push_back
const int maxN = 2600;
int n, m;
int a[maxN][maxN];
int d[maxN][maxN];
int c[maxN][maxN];
string s;
int cnt[maxN];
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 heuristic1() {
vector<pii> gornji;
for (int i = 1; i<=n; i++) {
for (int j = 1; j<=m; j++) {
if (a[i - 1][j] == 0 && a[i][j - 1] == 0 && a[i][j] == 1) gornji.pb({i, j});
}
}
random_shuffle(gornji.begin(), gornji.end());
for (int i = 1; i <=n; i++) {
cnt[i] = m;
}
for (int i = 0; i < min(400, (int) gornji.size()); i++) {
for (int len = 1; len <= n; len++) {
int x = gornji[i].first;
int y = gornji[i].second;
int lo = -1;
int ro = m + 1;
while(lo < ro - 1) {
int mid = lo + ro >> 1;
if (getDSum(x, y, x + len - 1, y + mid - 1) == len * mid) lo = mid; else ro = mid;
}
cnt[len] = min(cnt[len], lo);
}
}
int ans = 0;
for (int i = 1; i<=n; i++) {
ans = max(ans, i * cnt[i]);
}
return ans;
}
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 = minW * minH;
if (!check(minW, minH)) return heuristic1();
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 <=450 && m <=450) {
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;
}
Compilation message
bomb.cpp: In function 'int heuristic1()':
bomb.cpp:83:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
83 | int mid = lo + ro >> 1;
| ~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
18 ms |
30352 KB |
Output is correct |
4 |
Correct |
20 ms |
30448 KB |
Output is correct |
5 |
Correct |
38 ms |
340 KB |
Output is correct |
6 |
Correct |
6 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 |
1 ms |
468 KB |
Output isn't correct |
12 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
0 ms |
468 KB |
Output is correct |
15 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
1108 KB |
Output is correct |
18 |
Correct |
1 ms |
1108 KB |
Output is correct |
19 |
Incorrect |
1 ms |
1492 KB |
Output isn't correct |
20 |
Incorrect |
1 ms |
1492 KB |
Output isn't correct |
21 |
Correct |
1 ms |
980 KB |
Output is correct |
22 |
Correct |
2 ms |
1236 KB |
Output is 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 |
5 ms |
4692 KB |
Output is correct |
28 |
Incorrect |
6 ms |
5076 KB |
Output isn't correct |
29 |
Incorrect |
7 ms |
6484 KB |
Output isn't correct |
30 |
Incorrect |
10 ms |
7724 KB |
Output isn't correct |
31 |
Incorrect |
7 ms |
6100 KB |
Output isn't correct |
32 |
Incorrect |
8 ms |
6996 KB |
Output isn't correct |
33 |
Incorrect |
10 ms |
8020 KB |
Output isn't correct |
34 |
Incorrect |
5 ms |
5476 KB |
Output isn't correct |
35 |
Incorrect |
11 ms |
8020 KB |
Output isn't correct |
36 |
Correct |
10 ms |
8108 KB |
Output is correct |
37 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
38 |
Execution timed out |
1090 ms |
76576 KB |
Time limit exceeded |
39 |
Incorrect |
0 ms |
468 KB |
Output isn't correct |
40 |
Execution timed out |
1095 ms |
19836 KB |
Time limit exceeded |
41 |
Correct |
1 ms |
468 KB |
Output is correct |
42 |
Correct |
2 ms |
1620 KB |
Output is correct |
43 |
Execution timed out |
1087 ms |
76516 KB |
Time limit exceeded |
44 |
Correct |
14 ms |
8020 KB |
Output is correct |
45 |
Execution timed out |
1096 ms |
76592 KB |
Time limit exceeded |
46 |
Execution timed out |
1083 ms |
76616 KB |
Time limit exceeded |
47 |
Execution timed out |
1089 ms |
76560 KB |
Time limit exceeded |
48 |
Execution timed out |
1098 ms |
76540 KB |
Time limit exceeded |
49 |
Execution timed out |
1084 ms |
76532 KB |
Time limit exceeded |
50 |
Execution timed out |
1090 ms |
76612 KB |
Time limit exceeded |
51 |
Execution timed out |
1051 ms |
76644 KB |
Time limit exceeded |
52 |
Execution timed out |
1093 ms |
76520 KB |
Time limit exceeded |
53 |
Execution timed out |
1093 ms |
76528 KB |
Time limit exceeded |
54 |
Execution timed out |
1093 ms |
76576 KB |
Time limit exceeded |
55 |
Execution timed out |
1076 ms |
76636 KB |
Time limit exceeded |
56 |
Execution timed out |
1061 ms |
76620 KB |
Time limit exceeded |
57 |
Execution timed out |
1100 ms |
76624 KB |
Time limit exceeded |
58 |
Execution timed out |
1093 ms |
76568 KB |
Time limit exceeded |
59 |
Execution timed out |
1096 ms |
76620 KB |
Time limit exceeded |
60 |
Execution timed out |
1097 ms |
76528 KB |
Time limit exceeded |
61 |
Execution timed out |
1101 ms |
76548 KB |
Time limit exceeded |
62 |
Execution timed out |
1103 ms |
76552 KB |
Time limit exceeded |
63 |
Execution timed out |
1071 ms |
76552 KB |
Time limit exceeded |
64 |
Execution timed out |
1104 ms |
76560 KB |
Time limit exceeded |
65 |
Execution timed out |
1084 ms |
76540 KB |
Time limit exceeded |
66 |
Execution timed out |
1089 ms |
76576 KB |
Time limit exceeded |
67 |
Execution timed out |
1026 ms |
76588 KB |
Time limit exceeded |
68 |
Execution timed out |
1087 ms |
76528 KB |
Time limit exceeded |
69 |
Execution timed out |
1091 ms |
76556 KB |
Time limit exceeded |
70 |
Execution timed out |
1094 ms |
61304 KB |
Time limit exceeded |
71 |
Execution timed out |
1091 ms |
76600 KB |
Time limit exceeded |
72 |
Execution timed out |
1104 ms |
76512 KB |
Time limit exceeded |
73 |
Execution timed out |
1074 ms |
76624 KB |
Time limit exceeded |
74 |
Execution timed out |
1081 ms |
77456 KB |
Time limit exceeded |
75 |
Execution timed out |
1103 ms |
78212 KB |
Time limit exceeded |
76 |
Execution timed out |
1079 ms |
78184 KB |
Time limit exceeded |
77 |
Execution timed out |
1080 ms |
78176 KB |
Time limit exceeded |
78 |
Execution timed out |
1069 ms |
78396 KB |
Time limit exceeded |
79 |
Execution timed out |
1045 ms |
78152 KB |
Time limit exceeded |
80 |
Execution timed out |
1022 ms |
78280 KB |
Time limit exceeded |
81 |
Execution timed out |
1094 ms |
78300 KB |
Time limit exceeded |
82 |
Execution timed out |
1025 ms |
78416 KB |
Time limit exceeded |
83 |
Execution timed out |
1012 ms |
78324 KB |
Time limit exceeded |
84 |
Execution timed out |
1104 ms |
78352 KB |
Time limit exceeded |
85 |
Execution timed out |
1010 ms |
78412 KB |
Time limit exceeded |
86 |
Execution timed out |
1044 ms |
78304 KB |
Time limit exceeded |
87 |
Execution timed out |
1084 ms |
78352 KB |
Time limit exceeded |
88 |
Execution timed out |
1105 ms |
78424 KB |
Time limit exceeded |
89 |
Execution timed out |
1077 ms |
78416 KB |
Time limit exceeded |
90 |
Execution timed out |
1060 ms |
61248 KB |
Time limit exceeded |
91 |
Execution timed out |
1081 ms |
76604 KB |
Time limit exceeded |
92 |
Execution timed out |
1079 ms |
76612 KB |
Time limit exceeded |
93 |
Execution timed out |
1090 ms |
76552 KB |
Time limit exceeded |
94 |
Execution timed out |
1079 ms |
76560 KB |
Time limit exceeded |
95 |
Execution timed out |
1078 ms |
76532 KB |
Time limit exceeded |
96 |
Execution timed out |
1084 ms |
76512 KB |
Time limit exceeded |
97 |
Execution timed out |
1079 ms |
76680 KB |
Time limit exceeded |
98 |
Execution timed out |
1088 ms |
76580 KB |
Time limit exceeded |
99 |
Execution timed out |
1093 ms |
76612 KB |
Time limit exceeded |
100 |
Execution timed out |
1091 ms |
76508 KB |
Time limit exceeded |