#include <bits/stdc++.h>
#define pb push_back
#define sz(v) (int)v.size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define x first
#define y second
#define int long long
#define nl "\n"
using namespace std;
typedef long long ll;
typedef pair<long long, long long> pll;
typedef pair <ll, ll> pii;
const int N = (int)1e6 + 7;
const int M = (int)5e6 + 7;
const ll MOD = (ll)1e9 + 7;
const int inf = (int)1e9 + 7;
const ll INF = (ll)3e18 + 7;
pii dir[] = {{-1, -1}, {1, 1}, {-1, 1}, {1, -1}};
int n, m;
char c[2501][2501];
bool used[2501][2501];
void solve() {
cin >> n >> m;
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= m; ++j) {
cin >> c[i][j];
}
}
int ans = inf;
if(n == 1) {
int cur = 0;
for(int i = 1; i <= m; ++i) {
if(c[1][i] == '1') cur++;
else {
if(cur > 0) ans = min(ans, cur);
cur = 0;
}
}
if(c[1][m] == '1') ans = min(ans, cur);
cout << ans << nl;
return;
}
if(m == 1) {
int cur = 0;
for(int i = 1; i <= n; ++i) {
if(c[i][1] == '1') cur++;
else {
if(cur > 0) ans = min(ans, cur);
cur = 0;
}
}
if(c[n][1] == '1') ans = min(ans, cur);
cout << ans << nl;
return;
}
ans = 0;
for(int e = 1; e <= n; ++e) {
for(int f = 1; f <= n; ++f) {
bool ok = 1;
for(int i = 1; i <= n; ++i) fill(used[i] + 1, used[i] + 1 + m, 0);
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= n; ++j) {
if(i + e - 1 > n || j + f - 1 > m) break;
if(c[i][j] == '1') {
bool cur = 1;
for(int ii = i; ii <= i + e - 1 && cur; ++ii) {
for(int jj = j; jj <= j + f - 1 && cur; ++jj) {
cur &= (c[ii][jj] == '1');
}
}
if(cur) {
for(int ii = i; ii <= i + e - 1 && cur; ++ii) {
for(int jj = j; jj <= j + f - 1 && cur; ++jj) {
used[ii][jj] = 1;
}
}
}
}
}
}
for(int i = 1; i <= n && ok; ++i) {
for(int j = 1; j <= n && ok; ++j) {
if(c[i][j] == '1') ok &= (used[i][j] == 1);
}
}
if(ok) {
ans = max(ans, e * f);
//cout << e << ' ' << f << nl;
}
}
}
cout << ans << nl;
}
signed main() {
ios_base::sync_with_stdio(NULL);
cin.tie(0);
cout.tie(0);
int test = 1;
//cin >> test;
for(int i = 1; i <= test; ++i) {
//cout << "Case " << i << ": ";
solve();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
3 ms |
6348 KB |
Output is correct |
4 |
Correct |
2 ms |
6348 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
2 ms |
332 KB |
Output is correct |
17 |
Correct |
31 ms |
636 KB |
Output is correct |
18 |
Correct |
12 ms |
676 KB |
Output is correct |
19 |
Correct |
94 ms |
780 KB |
Output is correct |
20 |
Correct |
101 ms |
764 KB |
Output is correct |
21 |
Correct |
6 ms |
588 KB |
Output is correct |
22 |
Correct |
34 ms |
684 KB |
Output is correct |
23 |
Correct |
586 ms |
812 KB |
Output is correct |
24 |
Correct |
87 ms |
716 KB |
Output is correct |
25 |
Correct |
874 ms |
716 KB |
Output is correct |
26 |
Execution timed out |
1089 ms |
716 KB |
Time limit exceeded |
27 |
Execution timed out |
1072 ms |
1736 KB |
Time limit exceeded |
28 |
Execution timed out |
1089 ms |
1764 KB |
Time limit exceeded |
29 |
Execution timed out |
1064 ms |
2300 KB |
Time limit exceeded |
30 |
Execution timed out |
1076 ms |
2508 KB |
Time limit exceeded |
31 |
Execution timed out |
1080 ms |
1996 KB |
Time limit exceeded |
32 |
Execution timed out |
1077 ms |
2440 KB |
Time limit exceeded |
33 |
Execution timed out |
1078 ms |
2636 KB |
Time limit exceeded |
34 |
Execution timed out |
1094 ms |
2124 KB |
Time limit exceeded |
35 |
Execution timed out |
1086 ms |
2636 KB |
Time limit exceeded |
36 |
Execution timed out |
1046 ms |
2636 KB |
Time limit exceeded |
37 |
Correct |
1 ms |
332 KB |
Output is correct |
38 |
Execution timed out |
1004 ms |
14400 KB |
Time limit exceeded |
39 |
Correct |
2 ms |
332 KB |
Output is correct |
40 |
Execution timed out |
1068 ms |
5276 KB |
Time limit exceeded |
41 |
Correct |
1 ms |
332 KB |
Output is correct |
42 |
Execution timed out |
1032 ms |
708 KB |
Time limit exceeded |
43 |
Execution timed out |
1040 ms |
14356 KB |
Time limit exceeded |
44 |
Execution timed out |
1095 ms |
2624 KB |
Time limit exceeded |
45 |
Execution timed out |
1029 ms |
14352 KB |
Time limit exceeded |
46 |
Execution timed out |
1071 ms |
14352 KB |
Time limit exceeded |
47 |
Execution timed out |
1040 ms |
14400 KB |
Time limit exceeded |
48 |
Execution timed out |
1014 ms |
14404 KB |
Time limit exceeded |
49 |
Execution timed out |
1102 ms |
14420 KB |
Time limit exceeded |
50 |
Execution timed out |
1029 ms |
14356 KB |
Time limit exceeded |
51 |
Execution timed out |
1034 ms |
14344 KB |
Time limit exceeded |
52 |
Execution timed out |
1080 ms |
14408 KB |
Time limit exceeded |
53 |
Execution timed out |
1039 ms |
14412 KB |
Time limit exceeded |
54 |
Execution timed out |
1053 ms |
14420 KB |
Time limit exceeded |
55 |
Execution timed out |
1010 ms |
14408 KB |
Time limit exceeded |
56 |
Execution timed out |
1095 ms |
14320 KB |
Time limit exceeded |
57 |
Execution timed out |
1041 ms |
14440 KB |
Time limit exceeded |
58 |
Execution timed out |
1033 ms |
14400 KB |
Time limit exceeded |
59 |
Execution timed out |
1020 ms |
14348 KB |
Time limit exceeded |
60 |
Execution timed out |
1069 ms |
14412 KB |
Time limit exceeded |
61 |
Execution timed out |
1076 ms |
14404 KB |
Time limit exceeded |
62 |
Execution timed out |
1040 ms |
14476 KB |
Time limit exceeded |
63 |
Execution timed out |
1035 ms |
14404 KB |
Time limit exceeded |
64 |
Execution timed out |
1026 ms |
14324 KB |
Time limit exceeded |
65 |
Execution timed out |
1036 ms |
14444 KB |
Time limit exceeded |
66 |
Execution timed out |
1014 ms |
14484 KB |
Time limit exceeded |
67 |
Execution timed out |
1077 ms |
14420 KB |
Time limit exceeded |
68 |
Execution timed out |
1057 ms |
14404 KB |
Time limit exceeded |
69 |
Execution timed out |
1018 ms |
14384 KB |
Time limit exceeded |
70 |
Execution timed out |
1064 ms |
12232 KB |
Time limit exceeded |
71 |
Execution timed out |
1014 ms |
14404 KB |
Time limit exceeded |
72 |
Execution timed out |
1008 ms |
14308 KB |
Time limit exceeded |
73 |
Execution timed out |
1048 ms |
14368 KB |
Time limit exceeded |
74 |
Execution timed out |
1077 ms |
14320 KB |
Time limit exceeded |
75 |
Execution timed out |
1038 ms |
14360 KB |
Time limit exceeded |
76 |
Execution timed out |
1036 ms |
14372 KB |
Time limit exceeded |
77 |
Execution timed out |
1095 ms |
14372 KB |
Time limit exceeded |
78 |
Execution timed out |
1083 ms |
14408 KB |
Time limit exceeded |
79 |
Execution timed out |
1097 ms |
14424 KB |
Time limit exceeded |
80 |
Execution timed out |
1075 ms |
14372 KB |
Time limit exceeded |
81 |
Execution timed out |
1065 ms |
14388 KB |
Time limit exceeded |
82 |
Execution timed out |
1010 ms |
14404 KB |
Time limit exceeded |
83 |
Execution timed out |
1014 ms |
14332 KB |
Time limit exceeded |
84 |
Execution timed out |
1006 ms |
14436 KB |
Time limit exceeded |
85 |
Execution timed out |
1059 ms |
14348 KB |
Time limit exceeded |
86 |
Execution timed out |
1074 ms |
14416 KB |
Time limit exceeded |
87 |
Execution timed out |
1058 ms |
14492 KB |
Time limit exceeded |
88 |
Execution timed out |
1053 ms |
14352 KB |
Time limit exceeded |
89 |
Execution timed out |
1014 ms |
14440 KB |
Time limit exceeded |
90 |
Execution timed out |
1096 ms |
12224 KB |
Time limit exceeded |
91 |
Execution timed out |
1002 ms |
14316 KB |
Time limit exceeded |
92 |
Execution timed out |
1041 ms |
14440 KB |
Time limit exceeded |
93 |
Execution timed out |
1014 ms |
14384 KB |
Time limit exceeded |
94 |
Execution timed out |
1020 ms |
14404 KB |
Time limit exceeded |
95 |
Execution timed out |
1052 ms |
14408 KB |
Time limit exceeded |
96 |
Execution timed out |
1054 ms |
14516 KB |
Time limit exceeded |
97 |
Execution timed out |
1083 ms |
14412 KB |
Time limit exceeded |
98 |
Execution timed out |
1016 ms |
14420 KB |
Time limit exceeded |
99 |
Execution timed out |
1028 ms |
14612 KB |
Time limit exceeded |
100 |
Execution timed out |
1082 ms |
14644 KB |
Time limit exceeded |