#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int solve1(int n, int m, vector<string> s) {
vector<vector<int>> pr(n + 1, vector<int>(m + 1));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
int val = s[i][j] - '0';
pr[i + 1][j + 1] = val + pr[i + 1][j] + pr[i][j + 1] - pr[i][j];
}
}
int maxlen = n;
for (int j = 0; j < m; ++j) {
int L0 = 0;
for (int i = 0; i < n; ++i) {
if (s[i][j] == '1') {
L0++;
}
else {
if (L0) {
maxlen = min(maxlen, L0);
}
L0 = 0;
}
}
if (L0) {
maxlen = min(maxlen, L0);
}
}
int tl = 0, tr = m + 100;
while (tl < tr - 1) {
int tm = (tl + tr) >> 1;
//tm = 2;
bool ok = true;
vector<int> freeze(n);
for (int j = 0; j < m; ++j) {
if (!ok) break;
for (int i = 0; i < n; ++i) {
if (s[i][j] == '1') {
if (i + maxlen <= n && j + tm <= m) {
int S = pr[i + maxlen][j + tm] + pr[i][j] - pr[i + maxlen][j] - pr[i][j + tm];
if (S != (maxlen * tm) && !freeze[i]) {
// cout << i << ' ' << j << ' '<<tm << endl;
ok = false;
break;
}
if (S == (maxlen * tm)) {
for (int k = i; k < i + maxlen; ++k) {
freeze[k] = tm;
}
//i += maxlen - 1;
//continue;
}
}
else if (!freeze[i]) {
// cout << i << ' ' << j << ' ' << tm << endl;
ok = 0;
break;
}
freeze[i]--;
}
}
}
if (ok) {
//cout << "YES";
tl = tm;
}
else tr = tm;
}
return (maxlen * tl);
}
int main() {
int n, m;
cin >> n >> m;
vector<string> s(n);
for (int i = 0; i < n; ++i) cin >> s[i];
cout << solve1(n, m, s);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
620 KB |
Output is correct |
4 |
Correct |
1 ms |
620 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
9 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
512 KB |
Output is correct |
18 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
19 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
20 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
21 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
22 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
23 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
24 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
25 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
4 ms |
1004 KB |
Output is correct |
28 |
Incorrect |
5 ms |
1132 KB |
Output isn't correct |
29 |
Incorrect |
31 ms |
1388 KB |
Output isn't correct |
30 |
Incorrect |
8 ms |
1644 KB |
Output isn't correct |
31 |
Incorrect |
6 ms |
1388 KB |
Output isn't correct |
32 |
Incorrect |
6 ms |
1516 KB |
Output isn't correct |
33 |
Incorrect |
9 ms |
1772 KB |
Output isn't correct |
34 |
Incorrect |
3 ms |
876 KB |
Output isn't correct |
35 |
Incorrect |
8 ms |
1772 KB |
Output isn't correct |
36 |
Correct |
35 ms |
1772 KB |
Output is correct |
37 |
Incorrect |
1 ms |
492 KB |
Output isn't correct |
38 |
Correct |
507 ms |
41320 KB |
Output is correct |
39 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |
40 |
Incorrect |
157 ms |
5340 KB |
Output isn't correct |
41 |
Correct |
1 ms |
364 KB |
Output is correct |
42 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
43 |
Execution timed out |
1091 ms |
41196 KB |
Time limit exceeded |
44 |
Incorrect |
27 ms |
1772 KB |
Output isn't correct |
45 |
Execution timed out |
1087 ms |
41196 KB |
Time limit exceeded |
46 |
Correct |
409 ms |
41324 KB |
Output is correct |
47 |
Execution timed out |
1072 ms |
41324 KB |
Time limit exceeded |
48 |
Execution timed out |
1052 ms |
41196 KB |
Time limit exceeded |
49 |
Correct |
649 ms |
41300 KB |
Output is correct |
50 |
Correct |
791 ms |
41472 KB |
Output is correct |
51 |
Execution timed out |
1094 ms |
41196 KB |
Time limit exceeded |
52 |
Execution timed out |
1095 ms |
41196 KB |
Time limit exceeded |
53 |
Correct |
735 ms |
41324 KB |
Output is correct |
54 |
Correct |
502 ms |
41324 KB |
Output is correct |
55 |
Correct |
649 ms |
41324 KB |
Output is correct |
56 |
Correct |
328 ms |
41196 KB |
Output is correct |
57 |
Execution timed out |
1100 ms |
41196 KB |
Time limit exceeded |
58 |
Correct |
819 ms |
41348 KB |
Output is correct |
59 |
Correct |
879 ms |
41308 KB |
Output is correct |
60 |
Execution timed out |
1092 ms |
41196 KB |
Time limit exceeded |
61 |
Execution timed out |
1002 ms |
41324 KB |
Time limit exceeded |
62 |
Execution timed out |
1094 ms |
41196 KB |
Time limit exceeded |
63 |
Execution timed out |
1081 ms |
41196 KB |
Time limit exceeded |
64 |
Correct |
492 ms |
41324 KB |
Output is correct |
65 |
Execution timed out |
1051 ms |
41196 KB |
Time limit exceeded |
66 |
Correct |
617 ms |
41196 KB |
Output is correct |
67 |
Execution timed out |
1096 ms |
41196 KB |
Time limit exceeded |
68 |
Correct |
920 ms |
41260 KB |
Output is correct |
69 |
Execution timed out |
1093 ms |
41196 KB |
Time limit exceeded |
70 |
Incorrect |
188 ms |
28268 KB |
Output isn't correct |
71 |
Incorrect |
409 ms |
41320 KB |
Output isn't correct |
72 |
Incorrect |
496 ms |
41452 KB |
Output isn't correct |
73 |
Incorrect |
481 ms |
41196 KB |
Output isn't correct |
74 |
Incorrect |
488 ms |
41196 KB |
Output isn't correct |
75 |
Incorrect |
556 ms |
41324 KB |
Output isn't correct |
76 |
Incorrect |
476 ms |
41452 KB |
Output isn't correct |
77 |
Incorrect |
577 ms |
41324 KB |
Output isn't correct |
78 |
Incorrect |
487 ms |
41416 KB |
Output isn't correct |
79 |
Incorrect |
220 ms |
41196 KB |
Output isn't correct |
80 |
Incorrect |
219 ms |
41196 KB |
Output isn't correct |
81 |
Incorrect |
267 ms |
41196 KB |
Output isn't correct |
82 |
Incorrect |
542 ms |
41196 KB |
Output isn't correct |
83 |
Incorrect |
510 ms |
41324 KB |
Output isn't correct |
84 |
Incorrect |
234 ms |
41196 KB |
Output isn't correct |
85 |
Incorrect |
502 ms |
41196 KB |
Output isn't correct |
86 |
Incorrect |
479 ms |
41324 KB |
Output isn't correct |
87 |
Incorrect |
512 ms |
41324 KB |
Output isn't correct |
88 |
Incorrect |
526 ms |
41196 KB |
Output isn't correct |
89 |
Incorrect |
709 ms |
41452 KB |
Output isn't correct |
90 |
Incorrect |
242 ms |
28396 KB |
Output isn't correct |
91 |
Incorrect |
623 ms |
41272 KB |
Output isn't correct |
92 |
Incorrect |
751 ms |
41324 KB |
Output isn't correct |
93 |
Incorrect |
634 ms |
41360 KB |
Output isn't correct |
94 |
Incorrect |
687 ms |
41264 KB |
Output isn't correct |
95 |
Incorrect |
506 ms |
41196 KB |
Output isn't correct |
96 |
Incorrect |
496 ms |
41324 KB |
Output isn't correct |
97 |
Incorrect |
531 ms |
41324 KB |
Output isn't correct |
98 |
Incorrect |
726 ms |
41280 KB |
Output isn't correct |
99 |
Incorrect |
712 ms |
41324 KB |
Output isn't correct |
100 |
Incorrect |
693 ms |
41324 KB |
Output isn't correct |