// Why I am so dumb? :c
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
using namespace std;
typedef long long ll;
int pref[2505][2505];
int arr[2505][2505];
char s[2505][2505];
int n, m, ans;
bool cmp(pair<int,int> a, pair<int,int> b) {
return a.fi * a.se < b.fi * b.se;
}
int rectSum(int ax, int ay, int bx, int by) {
int ret = pref[bx][by];
ret -= pref[ax - 1][by];
ret -= pref[bx][ay - 1];
ret += pref[ax - 1][ay - 1];
return ret;
}
void updRect(int ax, int ay, int bx, int by) {
++arr[bx][by];
--arr[ax - 1][by];
--arr[bx][ay - 1];
++arr[ax - 1][ay - 1];
}
bool check(int x, int y, bool dbg = 0) {
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
arr[i][j] = 0;
}
}
for (int cx = x; cx <= n; ++cx) {
for (int cy = y; cy <= m; ++cy) {
if (rectSum(cx - x + 1, cy - y + 1, cx, cy) == x * y) {
if (dbg) {
printf("NEW RECT: ");
printf("%d %d\n", cx, cy);
}
updRect(cx - x + 1, cy - y + 1, cx, cy);
}
}
}
for (int i = n; i > 0; --i) {
for (int j = m; j > 0; --j) {
arr[i][j] -= arr[i + 1][j + 1];
arr[i][j] += arr[i + 1][j];
arr[i][j] += arr[i][j + 1];
}
}
bool good = 1;
if (dbg) {
printf("----------------------\n");
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
printf("%d ", arr[i][j]);
}
printf("\n");
}
printf("----------------------\n");
}
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
if (s[i][j] == '1' && arr[i][j] == 0) {
good = 0;
}
}
}
return good;
}
void solve() {
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; ++i) {
scanf("%s", s[i] + 1);
}
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
pref[i][j] = (s[i][j] - '0');
pref[i][j] += pref[i - 1][j];
pref[i][j] += pref[i][j - 1];
pref[i][j] -= pref[i - 1][j - 1];
}
}
int limx = n, limy = m;
for (int i = 1; i <= n; ++i) {
for (int l = 1, r; l <= m; l = r) {
r = l + 1;
if (s[i][l] == '0') {
continue;
}
while (s[i][l] == s[i][r]) {
++r;
}
limy = min(limy, r - l);
}
}
for (int i = 1; i <= m; ++i) {
for (int l = 1, r; l <= n; l = r) {
r = l + 1;
if (s[l][i] == '0') {
continue;
}
while (s[l][i] == s[r][i]) {
++r;
}
limx = min(limx, r - l);
}
}
ans = 1;
if (n > m) {
for (int cx = limx, cy = 0; cx > 0; --cx) {
if (cx * limy <= ans) {
break;
}
while (cy < limy && check(cx, cy + 1)) {
++cy;
}
ans = max(ans, cx * cy);
}
}
else {
for (int cy = limy, cx = 0; cy > 0; --cy) {
if (cy * limx <= ans) {
break;
}
while (cx < limx && check(cx + 1, cy)) {
++cx;
}
ans = max(ans, cx * cy);
}
}
printf("%d\n", ans);
}
int main() {
//freopen("bomb.in", "r", stdin);
//freopen("bomb.out", "w", stdout);
int tt = 1;
while (tt--) {
solve();
}
return 0;
}
Compilation message
bomb.cpp: In function 'void solve()':
bomb.cpp:101:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &n, &m);
~~~~~^~~~~~~~~~~~~~~~~
bomb.cpp:104:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%s", s[i] + 1);
~~~~~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
700 KB |
Output is correct |
3 |
Correct |
21 ms |
26740 KB |
Output is correct |
4 |
Correct |
21 ms |
26740 KB |
Output is correct |
5 |
Correct |
2 ms |
26740 KB |
Output is correct |
6 |
Correct |
2 ms |
26740 KB |
Output is correct |
7 |
Correct |
3 ms |
26740 KB |
Output is correct |
8 |
Correct |
3 ms |
26740 KB |
Output is correct |
9 |
Correct |
2 ms |
26740 KB |
Output is correct |
10 |
Correct |
2 ms |
26740 KB |
Output is correct |
11 |
Correct |
3 ms |
26740 KB |
Output is correct |
12 |
Correct |
2 ms |
26740 KB |
Output is correct |
13 |
Correct |
2 ms |
26740 KB |
Output is correct |
14 |
Correct |
2 ms |
26740 KB |
Output is correct |
15 |
Correct |
2 ms |
26740 KB |
Output is correct |
16 |
Correct |
2 ms |
26740 KB |
Output is correct |
17 |
Correct |
3 ms |
26740 KB |
Output is correct |
18 |
Correct |
3 ms |
26740 KB |
Output is correct |
19 |
Correct |
5 ms |
26740 KB |
Output is correct |
20 |
Correct |
5 ms |
26740 KB |
Output is correct |
21 |
Correct |
3 ms |
26740 KB |
Output is correct |
22 |
Correct |
3 ms |
26740 KB |
Output is correct |
23 |
Correct |
8 ms |
26740 KB |
Output is correct |
24 |
Correct |
4 ms |
26740 KB |
Output is correct |
25 |
Correct |
8 ms |
26740 KB |
Output is correct |
26 |
Correct |
5 ms |
26740 KB |
Output is correct |
27 |
Correct |
9 ms |
26740 KB |
Output is correct |
28 |
Correct |
15 ms |
26740 KB |
Output is correct |
29 |
Correct |
116 ms |
26740 KB |
Output is correct |
30 |
Correct |
208 ms |
26740 KB |
Output is correct |
31 |
Correct |
138 ms |
26740 KB |
Output is correct |
32 |
Correct |
136 ms |
26740 KB |
Output is correct |
33 |
Correct |
243 ms |
26740 KB |
Output is correct |
34 |
Correct |
16 ms |
26740 KB |
Output is correct |
35 |
Correct |
208 ms |
26740 KB |
Output is correct |
36 |
Correct |
107 ms |
26740 KB |
Output is correct |
37 |
Correct |
3 ms |
26740 KB |
Output is correct |
38 |
Execution timed out |
1080 ms |
63588 KB |
Time limit exceeded |
39 |
Correct |
4 ms |
63588 KB |
Output is correct |
40 |
Execution timed out |
1088 ms |
63588 KB |
Time limit exceeded |
41 |
Correct |
2 ms |
63588 KB |
Output is correct |
42 |
Correct |
8 ms |
63588 KB |
Output is correct |
43 |
Execution timed out |
1071 ms |
70364 KB |
Time limit exceeded |
44 |
Correct |
393 ms |
70364 KB |
Output is correct |
45 |
Execution timed out |
1077 ms |
76676 KB |
Time limit exceeded |
46 |
Execution timed out |
1092 ms |
82924 KB |
Time limit exceeded |
47 |
Execution timed out |
1091 ms |
89028 KB |
Time limit exceeded |
48 |
Execution timed out |
1077 ms |
95012 KB |
Time limit exceeded |
49 |
Correct |
423 ms |
101252 KB |
Output is correct |
50 |
Execution timed out |
1079 ms |
107236 KB |
Time limit exceeded |
51 |
Execution timed out |
1084 ms |
113476 KB |
Time limit exceeded |
52 |
Execution timed out |
1073 ms |
119460 KB |
Time limit exceeded |
53 |
Execution timed out |
1080 ms |
125712 KB |
Time limit exceeded |
54 |
Execution timed out |
1089 ms |
131812 KB |
Time limit exceeded |
55 |
Execution timed out |
1086 ms |
132096 KB |
Time limit exceeded |
56 |
Execution timed out |
1083 ms |
132096 KB |
Time limit exceeded |
57 |
Execution timed out |
1087 ms |
132096 KB |
Time limit exceeded |
58 |
Execution timed out |
1091 ms |
132096 KB |
Time limit exceeded |
59 |
Execution timed out |
1080 ms |
132096 KB |
Time limit exceeded |
60 |
Execution timed out |
1088 ms |
132096 KB |
Time limit exceeded |
61 |
Runtime error |
997 ms |
132096 KB |
Memory limit exceeded 132096 {'time-wall': '1.058', 'max-rss': '56696', 'csw-forced': '90', 'cg-mem': '132096', 'time': '0.997', 'csw-voluntary': '12'} 131072 |
62 |
Execution timed out |
1083 ms |
132096 KB |
Time limit exceeded |
63 |
Execution timed out |
1094 ms |
132096 KB |
Time limit exceeded |
64 |
Execution timed out |
1091 ms |
132096 KB |
Time limit exceeded |
65 |
Execution timed out |
1071 ms |
132096 KB |
Time limit exceeded |
66 |
Runtime error |
912 ms |
132096 KB |
Memory limit exceeded 132096 {'time-wall': '0.961', 'max-rss': '56696', 'csw-forced': '87', 'cg-mem': '132096', 'time': '0.912', 'csw-voluntary': '6'} 131072 |
67 |
Execution timed out |
1062 ms |
132096 KB |
Time limit exceeded |
68 |
Execution timed out |
1090 ms |
132096 KB |
Time limit exceeded |
69 |
Execution timed out |
1082 ms |
132096 KB |
Time limit exceeded |
70 |
Execution timed out |
1095 ms |
132096 KB |
Time limit exceeded |
71 |
Execution timed out |
1075 ms |
132096 KB |
Time limit exceeded |
72 |
Execution timed out |
1092 ms |
132096 KB |
Time limit exceeded |
73 |
Execution timed out |
1080 ms |
132096 KB |
Time limit exceeded |
74 |
Execution timed out |
1088 ms |
132096 KB |
Time limit exceeded |
75 |
Execution timed out |
1096 ms |
132096 KB |
Time limit exceeded |
76 |
Execution timed out |
1087 ms |
132096 KB |
Time limit exceeded |
77 |
Execution timed out |
1084 ms |
132096 KB |
Time limit exceeded |
78 |
Execution timed out |
1073 ms |
132096 KB |
Time limit exceeded |
79 |
Execution timed out |
1086 ms |
132096 KB |
Time limit exceeded |
80 |
Execution timed out |
1073 ms |
132096 KB |
Time limit exceeded |
81 |
Execution timed out |
1054 ms |
132096 KB |
Time limit exceeded |
82 |
Execution timed out |
1083 ms |
132096 KB |
Time limit exceeded |
83 |
Execution timed out |
1016 ms |
132096 KB |
Time limit exceeded |
84 |
Execution timed out |
1057 ms |
132096 KB |
Time limit exceeded |
85 |
Execution timed out |
1067 ms |
132096 KB |
Time limit exceeded |
86 |
Execution timed out |
1088 ms |
132096 KB |
Time limit exceeded |
87 |
Execution timed out |
1087 ms |
132096 KB |
Time limit exceeded |
88 |
Execution timed out |
1076 ms |
132096 KB |
Time limit exceeded |
89 |
Execution timed out |
1089 ms |
132096 KB |
Time limit exceeded |
90 |
Execution timed out |
1086 ms |
132096 KB |
Time limit exceeded |
91 |
Execution timed out |
1091 ms |
132096 KB |
Time limit exceeded |
92 |
Execution timed out |
1100 ms |
132096 KB |
Time limit exceeded |
93 |
Execution timed out |
1083 ms |
132096 KB |
Time limit exceeded |
94 |
Execution timed out |
1092 ms |
132096 KB |
Time limit exceeded |
95 |
Execution timed out |
1085 ms |
132096 KB |
Time limit exceeded |
96 |
Execution timed out |
1091 ms |
132096 KB |
Time limit exceeded |
97 |
Execution timed out |
1088 ms |
132096 KB |
Time limit exceeded |
98 |
Execution timed out |
1063 ms |
132096 KB |
Time limit exceeded |
99 |
Execution timed out |
1083 ms |
132096 KB |
Time limit exceeded |
100 |
Execution timed out |
1090 ms |
132096 KB |
Time limit exceeded |