#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <bitset>
#include <cstring>
#include <vector>
using namespace std;
const int N = 2505;
int dzaxic[N][N];
int ajic[N][N];
int a[N][N];
int n, m;
int M[N];
int mnw = 1000 * 1000 * 1000 + 5;
int mnh = mnw;
vector<pair<int, int> > v;
int main(){
ios_base::sync_with_stdio(false);
cin >> n >> m;
for (int i = 1; i <= n; i++){
for (int j = 1; j <= m; j++){
char c;
cin >> c;
a[i][j] = c - '0';
}
}
for (int i = 1; i <= n; i++)
{
int now = 0;
for (int j = 1; j <= m; j++){
if (a[i][j]){
now++;
dzaxic[i][j] = now;
}
else{
if (now) mnw = min(mnw, now);
now = 0;
}
}
if (now) mnw = min(mnw, now);
now = 0;
for (int j = m; j >= 1; j--){
if (a[i][j]){
now++;
ajic[i][j] = now;
}
else{
if (now) mnw = min(mnw, now);
now = 0;
}
}
if (now) mnw = min(mnw, now);
now = 0;
}
for (int j = 1; j <= m; j++){
int now = 0;
for (int i = 1; i <= n; i++){
if (a[i][j]){
now++;
}
else{
if (now) mnh = min(mnh, now);
now = 0;
}
}
if (now) mnh = min(mnh, now);
}
//cout << mnh << " " << mnw << endl;
/*for (int i = 1; i <= n; i++){
for (int j = 1; j <= m; j++){
cout <<ajic[i][j] << " ";
}
cout << endl;
}*/
for (int i = 1; i <= n; i++){
for (int j = 1; j <= m; j++){
/*if (i == 9 && j == 10){
cout << 0 << endl;
}*/
if (a[i][j] == 1 && a[i - 1][j] == 0 && a[i][j - 1] == 0 && a[i - 1][j - 1] == 0){
int now = -1;
//calc1(i, j, 1);
for (int ii = i; ii <= n; ii++){
if (a[ii][j] == 0) break;
if (now == -1 || ajic[ii][j] < now){
now = ajic[ii][j];
}
now = min(now, mnw);
v.push_back({ ii - i + 1, now });
if (ii - i + 1 >= mnh) break;
}
}
if (a[i][j] == 1 && a[i][j - 1] == 0 && a[i + 1][j - 1] == 0 && a[i+1][j] == 0){
int now = -1;
//calc1(i, j, -1);
for (int ii = i; ii >= 1; ii--){
if (a[ii][j] == 0) break;
if (now == -1 || ajic[ii][j] < now){
now = ajic[ii][j];
}
now = min(now, mnw);
v.push_back({ i - ii + 1, now });
if (i - ii + 1 >= mnh) break;
}
}
if (a[i][j] == 1 && a[i - 1][j] == 0 && a[i][j + 1] == 0 && a[i - 1][j + 1] == 0){
int now = -1;
for (int ii = i; ii <= n; ii++){
if (a[ii][j] == 0) break;
if (now == -1 || dzaxic[ii][j] < now){
now = dzaxic[ii][j];
}
now = min(now, mnw);
v.push_back({ ii - i + 1, now });
if (ii - i + 1 >= mnh) break;
}
}
if (a[i][j] == 1 && a[i + 1][j] == 0 && a[i][j + 1] == 0 && a[i + 1][j + 1] == 0){
int now = -1;
for (int ii = i; ii >= 1; ii--){
if (a[ii][j] == 0) break;
if (now == -1 || dzaxic[ii][j] < now){
now = dzaxic[ii][j];
}
now = min(now, mnw);
v.push_back({ i - ii + 1, now });
if (i - ii + 1 >= mnh) break;
}
}
}
}
// cout << mnh << " " << mnw << endl;
memset(M, -1, sizeof M);
for (int i = 0; i < v.size(); i++){
int a = v[i].first;
int b = v[i].second;
b = min(b, mnw);
if (M[a] == -1 || M[a] > b){
M[a] = b;
}
//cout << a << " " << b << endl;
}
int ans = 0;
for (int i = 0; i < v.size(); i++){
int a = v[i].first;
//a = min(a, mnh);
//if (a > mnh) continue;
int b = M[a];
a *= b;
ans = max(ans, a);
}
cout << ans << endl;
return 0;
}
Compilation message
bomb.cpp: In function 'int main()':
bomb.cpp:135:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < v.size(); i++){
~~^~~~~~~~~~
bomb.cpp:145:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < v.size(); i++){
~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
292 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
3 |
Correct |
19 ms |
30456 KB |
Output is correct |
4 |
Correct |
20 ms |
30408 KB |
Output is correct |
5 |
Correct |
2 ms |
380 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
504 KB |
Output is correct |
9 |
Correct |
2 ms |
632 KB |
Output is correct |
10 |
Correct |
2 ms |
504 KB |
Output is correct |
11 |
Correct |
2 ms |
604 KB |
Output is correct |
12 |
Correct |
2 ms |
504 KB |
Output is correct |
13 |
Correct |
2 ms |
504 KB |
Output is correct |
14 |
Correct |
2 ms |
508 KB |
Output is correct |
15 |
Correct |
2 ms |
504 KB |
Output is correct |
16 |
Correct |
2 ms |
632 KB |
Output is correct |
17 |
Correct |
2 ms |
1144 KB |
Output is correct |
18 |
Correct |
2 ms |
888 KB |
Output is correct |
19 |
Correct |
3 ms |
1248 KB |
Output is correct |
20 |
Correct |
3 ms |
1272 KB |
Output is correct |
21 |
Correct |
2 ms |
692 KB |
Output is correct |
22 |
Correct |
2 ms |
1016 KB |
Output is correct |
23 |
Correct |
3 ms |
1272 KB |
Output is correct |
24 |
Correct |
3 ms |
1144 KB |
Output is correct |
25 |
Correct |
3 ms |
1528 KB |
Output is correct |
26 |
Correct |
3 ms |
1656 KB |
Output is correct |
27 |
Correct |
7 ms |
4856 KB |
Output is correct |
28 |
Correct |
5 ms |
2424 KB |
Output is correct |
29 |
Correct |
10 ms |
6776 KB |
Output is correct |
30 |
Correct |
9 ms |
5752 KB |
Output is correct |
31 |
Correct |
8 ms |
4344 KB |
Output is correct |
32 |
Correct |
8 ms |
5464 KB |
Output is correct |
33 |
Correct |
10 ms |
6956 KB |
Output is correct |
34 |
Correct |
5 ms |
2680 KB |
Output is correct |
35 |
Correct |
8 ms |
3704 KB |
Output is correct |
36 |
Correct |
10 ms |
8312 KB |
Output is correct |
37 |
Correct |
2 ms |
636 KB |
Output is correct |
38 |
Correct |
205 ms |
75512 KB |
Output is correct |
39 |
Correct |
2 ms |
632 KB |
Output is correct |
40 |
Incorrect |
31 ms |
20728 KB |
Output isn't correct |
41 |
Correct |
2 ms |
632 KB |
Output is correct |
42 |
Correct |
3 ms |
1700 KB |
Output is correct |
43 |
Correct |
243 ms |
87996 KB |
Output is correct |
44 |
Correct |
11 ms |
8104 KB |
Output is correct |
45 |
Correct |
233 ms |
81504 KB |
Output is correct |
46 |
Correct |
209 ms |
75896 KB |
Output is correct |
47 |
Correct |
261 ms |
81560 KB |
Output is correct |
48 |
Correct |
233 ms |
76280 KB |
Output is correct |
49 |
Correct |
219 ms |
75588 KB |
Output is correct |
50 |
Correct |
236 ms |
76280 KB |
Output is correct |
51 |
Correct |
213 ms |
76356 KB |
Output is correct |
52 |
Correct |
207 ms |
76272 KB |
Output is correct |
53 |
Correct |
205 ms |
75640 KB |
Output is correct |
54 |
Correct |
205 ms |
63080 KB |
Output is correct |
55 |
Correct |
219 ms |
61352 KB |
Output is correct |
56 |
Correct |
280 ms |
79976 KB |
Output is correct |
57 |
Correct |
196 ms |
56176 KB |
Output is correct |
58 |
Correct |
217 ms |
61536 KB |
Output is correct |
59 |
Correct |
218 ms |
58452 KB |
Output is correct |
60 |
Correct |
230 ms |
68792 KB |
Output is correct |
61 |
Correct |
226 ms |
75880 KB |
Output is correct |
62 |
Correct |
215 ms |
75640 KB |
Output is correct |
63 |
Correct |
214 ms |
75640 KB |
Output is correct |
64 |
Correct |
196 ms |
58488 KB |
Output is correct |
65 |
Correct |
220 ms |
75160 KB |
Output is correct |
66 |
Correct |
206 ms |
71552 KB |
Output is correct |
67 |
Correct |
206 ms |
76228 KB |
Output is correct |
68 |
Correct |
205 ms |
76152 KB |
Output is correct |
69 |
Correct |
217 ms |
55528 KB |
Output is correct |
70 |
Correct |
119 ms |
31608 KB |
Output is correct |
71 |
Correct |
189 ms |
47368 KB |
Output is correct |
72 |
Correct |
191 ms |
52216 KB |
Output is correct |
73 |
Correct |
191 ms |
52728 KB |
Output is correct |
74 |
Correct |
199 ms |
55920 KB |
Output is correct |
75 |
Correct |
197 ms |
57484 KB |
Output is correct |
76 |
Correct |
194 ms |
58872 KB |
Output is correct |
77 |
Correct |
221 ms |
59392 KB |
Output is correct |
78 |
Correct |
195 ms |
59568 KB |
Output is correct |
79 |
Correct |
177 ms |
31780 KB |
Output is correct |
80 |
Correct |
202 ms |
33288 KB |
Output is correct |
81 |
Correct |
177 ms |
33688 KB |
Output is correct |
82 |
Correct |
205 ms |
62076 KB |
Output is correct |
83 |
Correct |
225 ms |
62200 KB |
Output is correct |
84 |
Correct |
192 ms |
27128 KB |
Output is correct |
85 |
Correct |
220 ms |
61216 KB |
Output is correct |
86 |
Correct |
223 ms |
74588 KB |
Output is correct |
87 |
Correct |
199 ms |
60176 KB |
Output is correct |
88 |
Correct |
217 ms |
61048 KB |
Output is correct |
89 |
Correct |
210 ms |
69624 KB |
Output is correct |
90 |
Correct |
131 ms |
45824 KB |
Output is correct |
91 |
Correct |
200 ms |
64892 KB |
Output is correct |
92 |
Correct |
220 ms |
66552 KB |
Output is correct |
93 |
Correct |
221 ms |
73724 KB |
Output is correct |
94 |
Correct |
224 ms |
68184 KB |
Output is correct |
95 |
Correct |
223 ms |
62200 KB |
Output is correct |
96 |
Correct |
223 ms |
61944 KB |
Output is correct |
97 |
Correct |
225 ms |
74488 KB |
Output is correct |
98 |
Correct |
222 ms |
61900 KB |
Output is correct |
99 |
Correct |
226 ms |
68088 KB |
Output is correct |
100 |
Correct |
222 ms |
73284 KB |
Output is correct |