# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
55452 |
2018-07-07T14:43:55 Z |
BThero |
Bomb (IZhO17_bomb) |
C++17 |
|
1000 ms |
132096 KB |
// 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);
}
}
for (int cx = limx, cy = 0; cx > 0; --cx) {
while (cy < limy && check(cx, cy + 1)) {
++cy;
}
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);
~~~~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
624 KB |
Output is correct |
3 |
Correct |
17 ms |
26548 KB |
Output is correct |
4 |
Correct |
18 ms |
26684 KB |
Output is correct |
5 |
Correct |
3 ms |
26684 KB |
Output is correct |
6 |
Correct |
2 ms |
26684 KB |
Output is correct |
7 |
Correct |
3 ms |
26684 KB |
Output is correct |
8 |
Correct |
2 ms |
26684 KB |
Output is correct |
9 |
Correct |
3 ms |
26684 KB |
Output is correct |
10 |
Correct |
3 ms |
26684 KB |
Output is correct |
11 |
Correct |
2 ms |
26684 KB |
Output is correct |
12 |
Correct |
2 ms |
26684 KB |
Output is correct |
13 |
Correct |
2 ms |
26684 KB |
Output is correct |
14 |
Correct |
2 ms |
26684 KB |
Output is correct |
15 |
Correct |
2 ms |
26684 KB |
Output is correct |
16 |
Correct |
3 ms |
26684 KB |
Output is correct |
17 |
Correct |
3 ms |
26684 KB |
Output is correct |
18 |
Correct |
3 ms |
26684 KB |
Output is correct |
19 |
Correct |
4 ms |
26684 KB |
Output is correct |
20 |
Correct |
4 ms |
26684 KB |
Output is correct |
21 |
Correct |
3 ms |
26684 KB |
Output is correct |
22 |
Correct |
4 ms |
26684 KB |
Output is correct |
23 |
Correct |
7 ms |
26684 KB |
Output is correct |
24 |
Correct |
4 ms |
26684 KB |
Output is correct |
25 |
Correct |
7 ms |
26684 KB |
Output is correct |
26 |
Correct |
4 ms |
26684 KB |
Output is correct |
27 |
Correct |
8 ms |
26684 KB |
Output is correct |
28 |
Correct |
17 ms |
26684 KB |
Output is correct |
29 |
Correct |
116 ms |
26684 KB |
Output is correct |
30 |
Correct |
302 ms |
26684 KB |
Output is correct |
31 |
Correct |
181 ms |
26684 KB |
Output is correct |
32 |
Correct |
184 ms |
26684 KB |
Output is correct |
33 |
Correct |
394 ms |
26684 KB |
Output is correct |
34 |
Correct |
14 ms |
26684 KB |
Output is correct |
35 |
Correct |
199 ms |
26684 KB |
Output is correct |
36 |
Correct |
51 ms |
26684 KB |
Output is correct |
37 |
Correct |
2 ms |
26684 KB |
Output is correct |
38 |
Execution timed out |
1075 ms |
63640 KB |
Time limit exceeded |
39 |
Correct |
3 ms |
63640 KB |
Output is correct |
40 |
Execution timed out |
1092 ms |
63640 KB |
Time limit exceeded |
41 |
Correct |
4 ms |
63640 KB |
Output is correct |
42 |
Correct |
13 ms |
63640 KB |
Output is correct |
43 |
Execution timed out |
1078 ms |
70660 KB |
Time limit exceeded |
44 |
Correct |
637 ms |
70660 KB |
Output is correct |
45 |
Execution timed out |
1075 ms |
76860 KB |
Time limit exceeded |
46 |
Execution timed out |
1069 ms |
83112 KB |
Time limit exceeded |
47 |
Execution timed out |
1079 ms |
89244 KB |
Time limit exceeded |
48 |
Execution timed out |
1076 ms |
95240 KB |
Time limit exceeded |
49 |
Correct |
325 ms |
101468 KB |
Output is correct |
50 |
Execution timed out |
1086 ms |
107492 KB |
Time limit exceeded |
51 |
Execution timed out |
1077 ms |
113656 KB |
Time limit exceeded |
52 |
Execution timed out |
1081 ms |
119736 KB |
Time limit exceeded |
53 |
Execution timed out |
1073 ms |
126000 KB |
Time limit exceeded |
54 |
Execution timed out |
1071 ms |
132056 KB |
Time limit exceeded |
55 |
Execution timed out |
1084 ms |
132096 KB |
Time limit exceeded |
56 |
Execution timed out |
1078 ms |
132096 KB |
Time limit exceeded |
57 |
Execution timed out |
1079 ms |
132096 KB |
Time limit exceeded |
58 |
Execution timed out |
1086 ms |
132096 KB |
Time limit exceeded |
59 |
Execution timed out |
1088 ms |
132096 KB |
Time limit exceeded |
60 |
Execution timed out |
1076 ms |
132096 KB |
Time limit exceeded |
61 |
Execution timed out |
1081 ms |
132096 KB |
Time limit exceeded |
62 |
Execution timed out |
1075 ms |
132096 KB |
Time limit exceeded |
63 |
Execution timed out |
1078 ms |
132096 KB |
Time limit exceeded |
64 |
Execution timed out |
1089 ms |
132096 KB |
Time limit exceeded |
65 |
Execution timed out |
1079 ms |
132096 KB |
Time limit exceeded |
66 |
Execution timed out |
1071 ms |
132096 KB |
Time limit exceeded |
67 |
Execution timed out |
1083 ms |
132096 KB |
Time limit exceeded |
68 |
Execution timed out |
1086 ms |
132096 KB |
Time limit exceeded |
69 |
Execution timed out |
1074 ms |
132096 KB |
Time limit exceeded |
70 |
Execution timed out |
1081 ms |
132096 KB |
Time limit exceeded |
71 |
Execution timed out |
1073 ms |
132096 KB |
Time limit exceeded |
72 |
Execution timed out |
1082 ms |
132096 KB |
Time limit exceeded |
73 |
Execution timed out |
1062 ms |
132096 KB |
Time limit exceeded |
74 |
Execution timed out |
1080 ms |
132096 KB |
Time limit exceeded |
75 |
Execution timed out |
1073 ms |
132096 KB |
Time limit exceeded |
76 |
Execution timed out |
1086 ms |
132096 KB |
Time limit exceeded |
77 |
Execution timed out |
1082 ms |
132096 KB |
Time limit exceeded |
78 |
Execution timed out |
1083 ms |
132096 KB |
Time limit exceeded |
79 |
Execution timed out |
1083 ms |
132096 KB |
Time limit exceeded |
80 |
Execution timed out |
1085 ms |
132096 KB |
Time limit exceeded |
81 |
Execution timed out |
1075 ms |
132096 KB |
Time limit exceeded |
82 |
Execution timed out |
1081 ms |
132096 KB |
Time limit exceeded |
83 |
Execution timed out |
1074 ms |
132096 KB |
Time limit exceeded |
84 |
Execution timed out |
1070 ms |
132096 KB |
Time limit exceeded |
85 |
Execution timed out |
1066 ms |
132096 KB |
Time limit exceeded |
86 |
Execution timed out |
1078 ms |
132096 KB |
Time limit exceeded |
87 |
Execution timed out |
1084 ms |
132096 KB |
Time limit exceeded |
88 |
Execution timed out |
1070 ms |
132096 KB |
Time limit exceeded |
89 |
Execution timed out |
1080 ms |
132096 KB |
Time limit exceeded |
90 |
Execution timed out |
1080 ms |
132096 KB |
Time limit exceeded |
91 |
Execution timed out |
1087 ms |
132096 KB |
Time limit exceeded |
92 |
Execution timed out |
1081 ms |
132096 KB |
Time limit exceeded |
93 |
Execution timed out |
1076 ms |
132096 KB |
Time limit exceeded |
94 |
Execution timed out |
1067 ms |
132096 KB |
Time limit exceeded |
95 |
Execution timed out |
1089 ms |
132096 KB |
Time limit exceeded |
96 |
Execution timed out |
1083 ms |
132096 KB |
Time limit exceeded |
97 |
Execution timed out |
1080 ms |
132096 KB |
Time limit exceeded |
98 |
Execution timed out |
1084 ms |
132096 KB |
Time limit exceeded |
99 |
Execution timed out |
1072 ms |
132096 KB |
Time limit exceeded |
100 |
Execution timed out |
1091 ms |
132096 KB |
Time limit exceeded |