# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
456418 |
2021-08-06T17:06:34 Z |
dxz05 |
Bomb (IZhO17_bomb) |
C++14 |
|
1000 ms |
61404 KB |
#pragma GCC optimize("Ofast,O2,O3")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << "[" << H << "]";
debug_out(T...);
}
#ifdef dddxxz
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
#define SZ(s) ((int)s.size())
#define all(x) (x).begin(), (x).end()
#define revall(x) (x).rbegin(), (x).rend()
clock_t startTime;
double getCurrentTime() {
return (double) (clock() - startTime) / CLOCKS_PER_SEC;
}
#define MP make_pair
typedef long long ll;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
const double eps = 0.00001;
const int MOD = 1e9;
const int INF = 1000000101;
const long long LLINF = 1223372000000000555;
const int N = 2e6 + 3e2;
const int M = 2522;
int n, m;
int a[M][M];
bool bomb[M][M];
int dp[M][M];
int sum(int x1, int y1, int x2, int y2){
if (min({x1, y1, x2, y2}) < 1 || max(x1, x2) > n || max(y1, y2) > m) return -1;
assert(x1 <= x2 && y1 <= y2);
int res = dp[x2][y2];
res -= dp[x1 - 1][y2];
res -= dp[x2][y1 - 1];
res += dp[x1 - 1][y1 - 1];
return res;
}
int ans = 0;
bool fill(int x1, int y1, int x2, int y2){
if (sum(x1, y1, x2, y2) != (x2 - x1 + 1) * (y2 - y1 + 1)) return false;
for (int i = x1; i <= x2; i++){
for (int j = y1; j <= y2; j++){
bomb[i][j] = true;
}
}
return true;
}
bool check(int A, int B){
if (ans > A * B) return true;
for (int i = 1; i <= n; i++){
for (int j = 1; j <= m; j++) bomb[i][j] = false;
}
for (int i = 1; i <= n - A + 1; i++){
for (int j = 1; j <= m - B + 1; j++){
if (!a[i][j] || bomb[i][j]) continue;
fill(i, j, i + A - 1, j + B - 1);
}
}
for (int i = 1; i <= n; i++){
for (int j = 1; j <= m; j++){
if (!a[i][j] || bomb[i][j]) continue;
if (fill(i, j, i + A - 1, j + B - 1)) continue;
if (fill(i - A + 1, j, i, j + B - 1)) continue;
if (fill(i, j - B + 1, i + A - 1, j)) continue;
if (fill(i - A + 1, j - B + 1, i, j)) continue;
return false;
}
}
ans = max(ans, A * B);
return true;
}
void solve(int TC) {
cin >> n >> m;
for (int i = 1; i <= n; i++){
for (int j = 1; j <= m; j++){
char ch;
cin >> ch;
a[i][j] = ch - '0';
dp[i][j] = dp[i][j - 1] + a[i][j];
}
}
for (int j = 1; j <= m; j++){
for (int i = 1; i <= n; i++){
dp[i][j] += dp[i - 1][j];
}
}
int A = n, B = m;
for (int j = 1; j <= m; j++){
for (int i = 1; i <= n; i++){
if (a[i][j] == 0) continue;
int k = i;
while (k <= n && a[k][j] == 1) k++;
A = min(A, k - i);
i = k - 1;
}
}
for (int i = 1; i <= n; i++){
for (int j = 1; j <= m; j++){
if (a[i][j] == 0) continue;
int k = j;
while (k <= m && a[i][k] == 1) k++;
B = min(B, k - j);
j = k - 1;
}
}
if (check(A, B)){
cout << ans;
return;
}
int l = 1, r = B;
while (l <= r){
int mid = (l + r) >> 1;
if (check(A, mid)){
l = mid + 1;
} else r = mid - 1;
}
l = 1, r = A;
while (l <= r){
int mid = (l + r) >> 1;
if (check(mid, B)){
l = mid + 1;
} else r = mid - 1;
}
cout << ans;
}
int main() {
startTime = clock();
cin.tie(nullptr);
cout.tie(nullptr);
ios_base::sync_with_stdio(false);
bool llololcal = false;
#ifdef dddxxz
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
llololcal = true;
#endif
int TC = 1;
//cin >> TC;
for (int test = 1; test <= TC; test++) {
debug(test);
//cout << "Case #" << test << ": ";
solve(test);
}
if (llololcal) cerr << endl << "Time: " << int(getCurrentTime() * 1000) << " ms" << endl;
return 0;
}
Compilation message
bomb.cpp: In function 'int main()':
bomb.cpp:19:20: warning: statement has no effect [-Wunused-value]
19 | #define debug(...) 42
| ^~
bomb.cpp:181:9: note: in expansion of macro 'debug'
181 | debug(test);
| ^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
13 ms |
26592 KB |
Output is correct |
4 |
Correct |
12 ms |
26564 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
324 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Incorrect |
1 ms |
512 KB |
Output isn't correct |
9 |
Incorrect |
1 ms |
452 KB |
Output isn't correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Incorrect |
1 ms |
460 KB |
Output isn't correct |
12 |
Correct |
1 ms |
448 KB |
Output is correct |
13 |
Correct |
1 ms |
460 KB |
Output is correct |
14 |
Correct |
1 ms |
448 KB |
Output is correct |
15 |
Incorrect |
1 ms |
460 KB |
Output isn't correct |
16 |
Correct |
1 ms |
460 KB |
Output is correct |
17 |
Incorrect |
1 ms |
972 KB |
Output isn't correct |
18 |
Incorrect |
1 ms |
1100 KB |
Output isn't correct |
19 |
Incorrect |
1 ms |
1356 KB |
Output isn't correct |
20 |
Incorrect |
2 ms |
1356 KB |
Output isn't correct |
21 |
Incorrect |
1 ms |
844 KB |
Output isn't correct |
22 |
Incorrect |
1 ms |
1100 KB |
Output isn't correct |
23 |
Incorrect |
2 ms |
1356 KB |
Output isn't correct |
24 |
Incorrect |
1 ms |
1228 KB |
Output isn't correct |
25 |
Incorrect |
2 ms |
1356 KB |
Output isn't correct |
26 |
Correct |
1 ms |
1356 KB |
Output is correct |
27 |
Correct |
5 ms |
4044 KB |
Output is correct |
28 |
Incorrect |
7 ms |
4300 KB |
Output isn't correct |
29 |
Incorrect |
16 ms |
5544 KB |
Output isn't correct |
30 |
Incorrect |
15 ms |
6476 KB |
Output isn't correct |
31 |
Incorrect |
12 ms |
5236 KB |
Output isn't correct |
32 |
Incorrect |
11 ms |
5976 KB |
Output isn't correct |
33 |
Incorrect |
18 ms |
6848 KB |
Output isn't correct |
34 |
Incorrect |
6 ms |
4684 KB |
Output isn't correct |
35 |
Incorrect |
11 ms |
6808 KB |
Output isn't correct |
36 |
Correct |
9 ms |
6732 KB |
Output is correct |
37 |
Correct |
1 ms |
460 KB |
Output is correct |
38 |
Correct |
209 ms |
61188 KB |
Output is correct |
39 |
Correct |
1 ms |
460 KB |
Output is correct |
40 |
Incorrect |
283 ms |
16292 KB |
Output isn't correct |
41 |
Incorrect |
1 ms |
460 KB |
Output isn't correct |
42 |
Incorrect |
2 ms |
1356 KB |
Output isn't correct |
43 |
Correct |
519 ms |
61220 KB |
Output is correct |
44 |
Incorrect |
55 ms |
6824 KB |
Output isn't correct |
45 |
Execution timed out |
1082 ms |
61160 KB |
Time limit exceeded |
46 |
Correct |
240 ms |
61196 KB |
Output is correct |
47 |
Execution timed out |
1083 ms |
61184 KB |
Time limit exceeded |
48 |
Incorrect |
415 ms |
61404 KB |
Output isn't correct |
49 |
Correct |
227 ms |
61124 KB |
Output is correct |
50 |
Incorrect |
462 ms |
61288 KB |
Output isn't correct |
51 |
Incorrect |
443 ms |
61252 KB |
Output isn't correct |
52 |
Incorrect |
453 ms |
61256 KB |
Output isn't correct |
53 |
Correct |
402 ms |
61340 KB |
Output is correct |
54 |
Correct |
424 ms |
61384 KB |
Output is correct |
55 |
Correct |
421 ms |
61392 KB |
Output is correct |
56 |
Correct |
211 ms |
61380 KB |
Output is correct |
57 |
Correct |
427 ms |
61340 KB |
Output is correct |
58 |
Correct |
525 ms |
61188 KB |
Output is correct |
59 |
Correct |
448 ms |
61216 KB |
Output is correct |
60 |
Correct |
218 ms |
61116 KB |
Output is correct |
61 |
Incorrect |
542 ms |
61120 KB |
Output isn't correct |
62 |
Correct |
241 ms |
61132 KB |
Output is correct |
63 |
Correct |
223 ms |
61016 KB |
Output is correct |
64 |
Correct |
221 ms |
61056 KB |
Output is correct |
65 |
Incorrect |
307 ms |
61012 KB |
Output isn't correct |
66 |
Correct |
708 ms |
61092 KB |
Output is correct |
67 |
Incorrect |
480 ms |
61020 KB |
Output isn't correct |
68 |
Correct |
536 ms |
61280 KB |
Output is correct |
69 |
Correct |
474 ms |
61084 KB |
Output is correct |
70 |
Incorrect |
237 ms |
48648 KB |
Output isn't correct |
71 |
Incorrect |
436 ms |
60972 KB |
Output isn't correct |
72 |
Incorrect |
459 ms |
60960 KB |
Output isn't correct |
73 |
Incorrect |
472 ms |
60832 KB |
Output isn't correct |
74 |
Incorrect |
499 ms |
60832 KB |
Output isn't correct |
75 |
Incorrect |
521 ms |
60952 KB |
Output isn't correct |
76 |
Incorrect |
514 ms |
60804 KB |
Output isn't correct |
77 |
Incorrect |
519 ms |
60828 KB |
Output isn't correct |
78 |
Incorrect |
507 ms |
60900 KB |
Output isn't correct |
79 |
Incorrect |
305 ms |
60888 KB |
Output isn't correct |
80 |
Incorrect |
313 ms |
61024 KB |
Output isn't correct |
81 |
Incorrect |
404 ms |
60832 KB |
Output isn't correct |
82 |
Incorrect |
479 ms |
60836 KB |
Output isn't correct |
83 |
Incorrect |
493 ms |
60828 KB |
Output isn't correct |
84 |
Incorrect |
336 ms |
60776 KB |
Output isn't correct |
85 |
Incorrect |
466 ms |
60832 KB |
Output isn't correct |
86 |
Incorrect |
399 ms |
60824 KB |
Output isn't correct |
87 |
Correct |
777 ms |
60832 KB |
Output is correct |
88 |
Incorrect |
460 ms |
60928 KB |
Output isn't correct |
89 |
Incorrect |
754 ms |
60832 KB |
Output isn't correct |
90 |
Incorrect |
632 ms |
48648 KB |
Output isn't correct |
91 |
Incorrect |
574 ms |
60832 KB |
Output isn't correct |
92 |
Execution timed out |
1090 ms |
60800 KB |
Time limit exceeded |
93 |
Incorrect |
396 ms |
61048 KB |
Output isn't correct |
94 |
Incorrect |
427 ms |
60712 KB |
Output isn't correct |
95 |
Incorrect |
498 ms |
60712 KB |
Output isn't correct |
96 |
Incorrect |
486 ms |
60676 KB |
Output isn't correct |
97 |
Incorrect |
424 ms |
60772 KB |
Output isn't correct |
98 |
Incorrect |
501 ms |
60704 KB |
Output isn't correct |
99 |
Incorrect |
875 ms |
60868 KB |
Output isn't correct |
100 |
Incorrect |
384 ms |
60560 KB |
Output isn't correct |