#include <bits/stdc++.h>
//#include <ext/pb_ds/detail/standard_policies.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx2")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
using namespace std;
//using namespace __gnu_pbds;
//template <typename T> using ordered_set = tree <T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 gen(time(0));
#define ll long long
#define ld long double
#define pb push_back
#define F first
#define S second
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define sz(a) int32_t(a.size())
#define endl '\n'
//#define int long long
const int N = 3100;
const int M = 31;
const int mod = 1e9 + 7;
const ll inf = 1e18 + 7;
int a[N][N], cnt[N][N], n, m;
bool good(int x, int y)
{
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++)
cnt[i][j] = 0;
for(int i = 0; i + x <= n; i++)
for(int j = 0; j + y <= m; j++)
{
int fl = 0;
for(int x1 = i; x1 < i + x; x1++)
{
for(int y1 = j; y1 < j + y; y1++)
{
if (!a[x1][y1])
{
fl = 1;
break;
}
}
if (fl) break;
}
if (fl) continue;
for(int x1 = i; x1 < i + x; x1++)
for(int y1 = j; y1 < j + y; y1++)
cnt[x1][y1] = 1;
}
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++)
if (a[i][j] && !cnt[i][j]) return 0;
return 1;
}
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#else
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif // LOCAL
cin >> n >> m;
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++)
{
char c;
cin >> c;
a[i][j] = int32_t(c - '0');
}
int x = m, y = n, ls = 0;
for(int i = 0; i < n; i++)
{
ls = -1;
for(int j = 0; j < m; j++)
{
if (!a[i][j])
{
if (j && a[i][j - 1]) x = min(x, j - ls - 1);
ls = j;
}
}
if (ls != m - 1) x = min(x, m - ls - 1);
}
for(int j = 0; j < m; j++)
{
ls = -1;
for(int i = 0; i < n; i++)
{
if (!a[i][j])
{
if (i && a[i - 1][j]) y = min(y, i - ls - 1);
ls = i;
}
}
if (ls != n - 1) y = min(y, n - ls - 1);
}
int ans = 0;
for(int i = 1; i <= n; i++)
{
for(int j = m; j >= 1; j--)
{
if (!good(i, j)) continue;
ans = max(ans, i * j);
if (i * j > x * y)
{
cout << -1;
return 0;
}
break;
}
}
if (ans < x * y) return 1;
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Execution timed out |
1087 ms |
20428 KB |
Time limit exceeded |
4 |
Execution timed out |
1086 ms |
20428 KB |
Time limit exceeded |
5 |
Correct |
381 ms |
336 KB |
Output is correct |
6 |
Correct |
120 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Runtime error |
1 ms |
460 KB |
Execution failed because the return code was nonzero |
9 |
Runtime error |
1 ms |
460 KB |
Execution failed because the return code was nonzero |
10 |
Runtime error |
1 ms |
332 KB |
Execution failed because the return code was nonzero |
11 |
Runtime error |
1 ms |
460 KB |
Execution failed because the return code was nonzero |
12 |
Runtime error |
0 ms |
332 KB |
Execution failed because the return code was nonzero |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
452 KB |
Output is correct |
15 |
Runtime error |
1 ms |
460 KB |
Execution failed because the return code was nonzero |
16 |
Correct |
2 ms |
460 KB |
Output is correct |
17 |
Correct |
33 ms |
844 KB |
Output is correct |
18 |
Runtime error |
16 ms |
844 KB |
Execution failed because the return code was nonzero |
19 |
Runtime error |
123 ms |
1100 KB |
Execution failed because the return code was nonzero |
20 |
Runtime error |
134 ms |
1100 KB |
Execution failed because the return code was nonzero |
21 |
Runtime error |
14 ms |
716 KB |
Execution failed because the return code was nonzero |
22 |
Runtime error |
38 ms |
972 KB |
Execution failed because the return code was nonzero |
23 |
Runtime error |
687 ms |
1100 KB |
Execution failed because the return code was nonzero |
24 |
Runtime error |
91 ms |
972 KB |
Execution failed because the return code was nonzero |
25 |
Runtime error |
984 ms |
1100 KB |
Execution failed because the return code was nonzero |
26 |
Execution timed out |
1084 ms |
1100 KB |
Time limit exceeded |
27 |
Execution timed out |
1097 ms |
3276 KB |
Time limit exceeded |
28 |
Execution timed out |
1092 ms |
3404 KB |
Time limit exceeded |
29 |
Execution timed out |
1092 ms |
4428 KB |
Time limit exceeded |
30 |
Execution timed out |
1099 ms |
5196 KB |
Time limit exceeded |
31 |
Execution timed out |
1099 ms |
4044 KB |
Time limit exceeded |
32 |
Execution timed out |
1090 ms |
4684 KB |
Time limit exceeded |
33 |
Execution timed out |
1094 ms |
5452 KB |
Time limit exceeded |
34 |
Execution timed out |
1096 ms |
3788 KB |
Time limit exceeded |
35 |
Execution timed out |
1092 ms |
5452 KB |
Time limit exceeded |
36 |
Execution timed out |
1092 ms |
5452 KB |
Time limit exceeded |
37 |
Runtime error |
1 ms |
460 KB |
Execution failed because the return code was nonzero |
38 |
Execution timed out |
1092 ms |
60852 KB |
Time limit exceeded |
39 |
Runtime error |
1 ms |
460 KB |
Execution failed because the return code was nonzero |
40 |
Execution timed out |
1093 ms |
13368 KB |
Time limit exceeded |
41 |
Runtime error |
1 ms |
460 KB |
Execution failed because the return code was nonzero |
42 |
Execution timed out |
1089 ms |
1100 KB |
Time limit exceeded |
43 |
Execution timed out |
1089 ms |
60852 KB |
Time limit exceeded |
44 |
Execution timed out |
1091 ms |
5452 KB |
Time limit exceeded |
45 |
Execution timed out |
1094 ms |
60904 KB |
Time limit exceeded |
46 |
Execution timed out |
1089 ms |
60900 KB |
Time limit exceeded |
47 |
Execution timed out |
1094 ms |
60956 KB |
Time limit exceeded |
48 |
Execution timed out |
1099 ms |
60868 KB |
Time limit exceeded |
49 |
Execution timed out |
1092 ms |
60944 KB |
Time limit exceeded |
50 |
Execution timed out |
1094 ms |
60856 KB |
Time limit exceeded |
51 |
Execution timed out |
1082 ms |
60904 KB |
Time limit exceeded |
52 |
Execution timed out |
1089 ms |
60852 KB |
Time limit exceeded |
53 |
Execution timed out |
1096 ms |
60964 KB |
Time limit exceeded |
54 |
Execution timed out |
1094 ms |
60924 KB |
Time limit exceeded |
55 |
Execution timed out |
1097 ms |
60880 KB |
Time limit exceeded |
56 |
Execution timed out |
1094 ms |
60848 KB |
Time limit exceeded |
57 |
Execution timed out |
1100 ms |
60868 KB |
Time limit exceeded |
58 |
Execution timed out |
1093 ms |
60868 KB |
Time limit exceeded |
59 |
Execution timed out |
1096 ms |
60920 KB |
Time limit exceeded |
60 |
Execution timed out |
1086 ms |
60872 KB |
Time limit exceeded |
61 |
Execution timed out |
1095 ms |
60952 KB |
Time limit exceeded |
62 |
Execution timed out |
1059 ms |
60972 KB |
Time limit exceeded |
63 |
Execution timed out |
1079 ms |
60848 KB |
Time limit exceeded |
64 |
Execution timed out |
1098 ms |
60944 KB |
Time limit exceeded |
65 |
Execution timed out |
1080 ms |
60868 KB |
Time limit exceeded |
66 |
Execution timed out |
1097 ms |
60868 KB |
Time limit exceeded |
67 |
Execution timed out |
1078 ms |
60948 KB |
Time limit exceeded |
68 |
Execution timed out |
1089 ms |
60848 KB |
Time limit exceeded |
69 |
Execution timed out |
1093 ms |
60948 KB |
Time limit exceeded |
70 |
Execution timed out |
1095 ms |
47556 KB |
Time limit exceeded |
71 |
Execution timed out |
1096 ms |
60848 KB |
Time limit exceeded |
72 |
Execution timed out |
1085 ms |
60852 KB |
Time limit exceeded |
73 |
Execution timed out |
1096 ms |
60912 KB |
Time limit exceeded |
74 |
Execution timed out |
1098 ms |
60868 KB |
Time limit exceeded |
75 |
Execution timed out |
1100 ms |
60952 KB |
Time limit exceeded |
76 |
Execution timed out |
1094 ms |
60964 KB |
Time limit exceeded |
77 |
Execution timed out |
1049 ms |
60868 KB |
Time limit exceeded |
78 |
Execution timed out |
1081 ms |
60972 KB |
Time limit exceeded |
79 |
Execution timed out |
1089 ms |
60892 KB |
Time limit exceeded |
80 |
Execution timed out |
1103 ms |
60856 KB |
Time limit exceeded |
81 |
Execution timed out |
1087 ms |
60920 KB |
Time limit exceeded |
82 |
Execution timed out |
1097 ms |
60884 KB |
Time limit exceeded |
83 |
Execution timed out |
1088 ms |
60868 KB |
Time limit exceeded |
84 |
Execution timed out |
1104 ms |
60868 KB |
Time limit exceeded |
85 |
Execution timed out |
1096 ms |
60868 KB |
Time limit exceeded |
86 |
Execution timed out |
1099 ms |
60868 KB |
Time limit exceeded |
87 |
Execution timed out |
1095 ms |
60868 KB |
Time limit exceeded |
88 |
Execution timed out |
1091 ms |
60948 KB |
Time limit exceeded |
89 |
Execution timed out |
1081 ms |
60944 KB |
Time limit exceeded |
90 |
Execution timed out |
1083 ms |
47684 KB |
Time limit exceeded |
91 |
Execution timed out |
1089 ms |
60872 KB |
Time limit exceeded |
92 |
Execution timed out |
1093 ms |
60872 KB |
Time limit exceeded |
93 |
Execution timed out |
1096 ms |
60868 KB |
Time limit exceeded |
94 |
Execution timed out |
1081 ms |
60868 KB |
Time limit exceeded |
95 |
Execution timed out |
1096 ms |
60868 KB |
Time limit exceeded |
96 |
Execution timed out |
1090 ms |
60892 KB |
Time limit exceeded |
97 |
Execution timed out |
1089 ms |
60868 KB |
Time limit exceeded |
98 |
Execution timed out |
1097 ms |
60852 KB |
Time limit exceeded |
99 |
Execution timed out |
1062 ms |
60956 KB |
Time limit exceeded |
100 |
Execution timed out |
1098 ms |
60868 KB |
Time limit exceeded |