# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
173183 |
2020-01-03T14:38:51 Z |
VEGAnn |
Bomb (IZhO17_bomb) |
C++14 |
|
1000 ms |
98808 KB |
#include <bits/stdc++.h>
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define sz(x) ((int)x.size())
#define MP make_pair
#define ft first
#define sd second
#define pii pair<int, int>
#define PB push_back
using namespace std;
using namespace __gnu_pbds;
typedef long double ld;
typedef long long ll;
template <class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int N = 2510;
const int oo = 2e9;
int n, m, ans, a[N][N], mx = oo, pref[N][N], an1;
short pr[N][N], best[N], nt[N][N], down[N][2], up[N][2];
short pl[N][N], vl[N][N];
stack<int> st;
bool ok(int ht, int wd){
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
pl[i][j] = 0;
bool was = 1;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++){
if (i + ht - 1 > n || j + wd - 1 > m)
break;
int i1 = i + ht - 1, i2 = i - 1;
int j1 = j + wd - 1, j2 = j - 1;
int kol = pref[i1][j1] - pref[i2][j1] - pref[i1][j2] + pref[i2][j2];
if (kol > 0) continue;
was = 1;
pl[i][j]++; pl[i][j + wd]--;
pl[i + ht][j]--; pl[i + ht][j + wd]++;
}
if (!was) return 0;
for (int i = 1; i <= n; i++){
int cr = 0;
for (int j = 1; j <= m; j++){
cr += pl[i][j];
vl[i][j] = cr;
}
}
for (int j = 1; j <= m; j++){
int cr = 0;
for (int i = 1; i <= n; i++){
cr += vl[i][j];
if (a[i][j] == 1 && cr == 0)
return 0;
}
}
return 1;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
// freopen("in.txt","r",stdin);
ll sta = chrono::system_clock().now().time_since_epoch().count();
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 == '1' ? 1 : 0);
pref[i][j] = (a[i][j] ^ 1) + pref[i - 1][j] + pref[i][j - 1] - pref[i - 1][j - 1];
}
for (int j = 1; j <= m; j++){
for (int i = 1; i <= n; ){
if (a[i][j] == 0)
i++;
else {
int i1 = i;
while (i1 <= n && a[i1][j] == 1)
i1++;
mx = min(mx, i1 - i);
i = i1;
}
}
}
if (mx == oo){
cout << n * m;
return 0;
}
fill(best, best + n + 1, N);
for (int i = 1; i <= n; i++){
int pre = 0;
for (int j = 1; j <= m; j++){
if (a[i][j] == 0)
pre = j;
pr[i][j] = pre + 1;
}
pre = m + 1;
for (int j = m; j > 0; j--){
if (a[i][j] == 0)
pre = j;
nt[i][j] = pre - 1;
}
}
for (int j = 1; j <= m; j++){
for (int i = 1; i <= n; ){
if (a[i][j] == 0)
i++;
else {
int i1 = i;
while (i1 <= n && a[i1][j] == 1)
i1++;
while (sz(st)) st.pop();
for (int ii = i; ii < i1; ii++){
while (sz(st) && pr[st.top()][j] <= pr[ii][j])
st.pop();
down[ii][0] = (sz(st) == 0 ? i : st.top() + 1);
st.push(ii);
}
while (sz(st)) st.pop();
for (int ii = i; ii < i1; ii++){
while (sz(st) && nt[st.top()][j] >= nt[ii][j])
st.pop();
down[ii][1] = (sz(st) == 0 ? i : st.top() + 1);
st.push(ii);
}
while (sz(st)) st.pop();
for (int ii = i1 - 1; ii >= i; ii--){
while (sz(st) && pr[st.top()][j] <= pr[ii][j])
st.pop();
up[ii][0] = (sz(st) == 0 ? i1 - 1 : st.top() - 1);
st.push(ii);
}
while (sz(st)) st.pop();
for (int ii = i1 - 1; ii >= i; ii--){
while (sz(st) && nt[st.top()][j] >= nt[ii][j])
st.pop();
up[ii][1] = (sz(st) == 0 ? i1 - 1 : st.top() - 1);
st.push(ii);
}
i = i1;
}
}
for (int i = 1; i <= n; i++){
if (a[i][j] == 0) continue;
int l = max(down[i][0], down[i][1]);
int r = min(up[i][0], up[i][1]);
int cur = r - l + 1;
best[cur] = min(best[cur], short(nt[i][j] - pr[i][j] + 1));
}
}
best[n + 1] = N;
for (int i = n; i > 0; i--) {
best[i] = min(best[i + 1], best[i]);
if (best[i] < N && i <= mx)
ans = max(ans, best[i] * i);
}
bool full = 0;
int wd = m;
for (int ht = 1; ht <= n; ht++){
ll tim = chrono::system_clock().now().time_since_epoch().count();;
if (tim - sta > ll(1e9) - ll(1e7)) break;
while (wd > 0 && !ok(ht, wd))
wd--;
if (wd == 0) {
full = 1;
break;
}
if (n * wd <= ans) {
full = 1;
break;
}
if (ht == n)
full = 1;
an1 = max(an1, ht * wd);
}
// if (!full) return -1;
if (full)
cout << an1;
else cout << max(ans, an1);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Correct |
2 ms |
888 KB |
Output is correct |
3 |
Correct |
60 ms |
60536 KB |
Output is correct |
4 |
Correct |
64 ms |
60508 KB |
Output is correct |
5 |
Incorrect |
13 ms |
376 KB |
Output isn't correct |
6 |
Incorrect |
4 ms |
376 KB |
Output isn't correct |
7 |
Correct |
2 ms |
504 KB |
Output is correct |
8 |
Correct |
2 ms |
888 KB |
Output is correct |
9 |
Correct |
2 ms |
888 KB |
Output is correct |
10 |
Correct |
2 ms |
760 KB |
Output is correct |
11 |
Correct |
2 ms |
888 KB |
Output is correct |
12 |
Correct |
2 ms |
760 KB |
Output is correct |
13 |
Correct |
2 ms |
764 KB |
Output is correct |
14 |
Correct |
2 ms |
732 KB |
Output is correct |
15 |
Correct |
2 ms |
760 KB |
Output is correct |
16 |
Correct |
2 ms |
888 KB |
Output is correct |
17 |
Correct |
4 ms |
2040 KB |
Output is correct |
18 |
Correct |
4 ms |
2172 KB |
Output is correct |
19 |
Correct |
6 ms |
2808 KB |
Output is correct |
20 |
Correct |
6 ms |
2680 KB |
Output is correct |
21 |
Correct |
4 ms |
1656 KB |
Output is correct |
22 |
Correct |
5 ms |
2296 KB |
Output is correct |
23 |
Correct |
7 ms |
2924 KB |
Output is correct |
24 |
Correct |
5 ms |
2424 KB |
Output is correct |
25 |
Incorrect |
7 ms |
2992 KB |
Output isn't correct |
26 |
Correct |
8 ms |
2988 KB |
Output is correct |
27 |
Correct |
73 ms |
8780 KB |
Output is correct |
28 |
Correct |
99 ms |
9148 KB |
Output is correct |
29 |
Correct |
214 ms |
11740 KB |
Output is correct |
30 |
Incorrect |
219 ms |
13660 KB |
Output isn't correct |
31 |
Incorrect |
164 ms |
10832 KB |
Output isn't correct |
32 |
Incorrect |
139 ms |
12636 KB |
Output isn't correct |
33 |
Correct |
257 ms |
14428 KB |
Output is correct |
34 |
Correct |
55 ms |
10232 KB |
Output is correct |
35 |
Correct |
248 ms |
14456 KB |
Output is correct |
36 |
Correct |
353 ms |
14424 KB |
Output is correct |
37 |
Correct |
2 ms |
888 KB |
Output is correct |
38 |
Execution timed out |
1074 ms |
98692 KB |
Time limit exceeded |
39 |
Correct |
2 ms |
888 KB |
Output is correct |
40 |
Incorrect |
978 ms |
30712 KB |
Output isn't correct |
41 |
Incorrect |
2 ms |
888 KB |
Output isn't correct |
42 |
Correct |
8 ms |
2936 KB |
Output is correct |
43 |
Execution timed out |
1071 ms |
98708 KB |
Time limit exceeded |
44 |
Correct |
296 ms |
14328 KB |
Output is correct |
45 |
Execution timed out |
1072 ms |
98568 KB |
Time limit exceeded |
46 |
Execution timed out |
1084 ms |
98664 KB |
Time limit exceeded |
47 |
Execution timed out |
1071 ms |
98564 KB |
Time limit exceeded |
48 |
Execution timed out |
1088 ms |
98672 KB |
Time limit exceeded |
49 |
Execution timed out |
1006 ms |
74232 KB |
Time limit exceeded |
50 |
Execution timed out |
1088 ms |
98680 KB |
Time limit exceeded |
51 |
Execution timed out |
1090 ms |
98680 KB |
Time limit exceeded |
52 |
Execution timed out |
1087 ms |
98680 KB |
Time limit exceeded |
53 |
Execution timed out |
1081 ms |
98680 KB |
Time limit exceeded |
54 |
Execution timed out |
1093 ms |
98808 KB |
Time limit exceeded |
55 |
Execution timed out |
1092 ms |
98680 KB |
Time limit exceeded |
56 |
Execution timed out |
1090 ms |
98572 KB |
Time limit exceeded |
57 |
Execution timed out |
1084 ms |
98680 KB |
Time limit exceeded |
58 |
Execution timed out |
1089 ms |
98676 KB |
Time limit exceeded |
59 |
Execution timed out |
1087 ms |
98700 KB |
Time limit exceeded |
60 |
Execution timed out |
1091 ms |
98704 KB |
Time limit exceeded |
61 |
Execution timed out |
1082 ms |
98768 KB |
Time limit exceeded |
62 |
Execution timed out |
1093 ms |
98756 KB |
Time limit exceeded |
63 |
Execution timed out |
1088 ms |
98680 KB |
Time limit exceeded |
64 |
Execution timed out |
1085 ms |
98680 KB |
Time limit exceeded |
65 |
Execution timed out |
1085 ms |
98664 KB |
Time limit exceeded |
66 |
Execution timed out |
1075 ms |
98576 KB |
Time limit exceeded |
67 |
Execution timed out |
1099 ms |
98680 KB |
Time limit exceeded |
68 |
Execution timed out |
1067 ms |
98780 KB |
Time limit exceeded |
69 |
Execution timed out |
1081 ms |
98680 KB |
Time limit exceeded |
70 |
Execution timed out |
1087 ms |
79100 KB |
Time limit exceeded |
71 |
Execution timed out |
1079 ms |
98684 KB |
Time limit exceeded |
72 |
Execution timed out |
1095 ms |
98680 KB |
Time limit exceeded |
73 |
Execution timed out |
1084 ms |
98764 KB |
Time limit exceeded |
74 |
Execution timed out |
1077 ms |
98688 KB |
Time limit exceeded |
75 |
Execution timed out |
1077 ms |
98680 KB |
Time limit exceeded |
76 |
Execution timed out |
1090 ms |
98680 KB |
Time limit exceeded |
77 |
Execution timed out |
1093 ms |
98680 KB |
Time limit exceeded |
78 |
Execution timed out |
1092 ms |
98680 KB |
Time limit exceeded |
79 |
Execution timed out |
1089 ms |
98680 KB |
Time limit exceeded |
80 |
Execution timed out |
1088 ms |
98724 KB |
Time limit exceeded |
81 |
Execution timed out |
1087 ms |
98732 KB |
Time limit exceeded |
82 |
Execution timed out |
1085 ms |
98680 KB |
Time limit exceeded |
83 |
Execution timed out |
1087 ms |
98552 KB |
Time limit exceeded |
84 |
Execution timed out |
1085 ms |
98596 KB |
Time limit exceeded |
85 |
Execution timed out |
1083 ms |
98720 KB |
Time limit exceeded |
86 |
Execution timed out |
1059 ms |
98700 KB |
Time limit exceeded |
87 |
Execution timed out |
1083 ms |
98684 KB |
Time limit exceeded |
88 |
Execution timed out |
1087 ms |
98672 KB |
Time limit exceeded |
89 |
Execution timed out |
1067 ms |
98568 KB |
Time limit exceeded |
90 |
Execution timed out |
1065 ms |
78964 KB |
Time limit exceeded |
91 |
Execution timed out |
1076 ms |
98572 KB |
Time limit exceeded |
92 |
Execution timed out |
1066 ms |
98680 KB |
Time limit exceeded |
93 |
Execution timed out |
1093 ms |
98576 KB |
Time limit exceeded |
94 |
Execution timed out |
1068 ms |
98588 KB |
Time limit exceeded |
95 |
Execution timed out |
1067 ms |
98568 KB |
Time limit exceeded |
96 |
Execution timed out |
1087 ms |
98688 KB |
Time limit exceeded |
97 |
Execution timed out |
1074 ms |
98564 KB |
Time limit exceeded |
98 |
Execution timed out |
1091 ms |
98572 KB |
Time limit exceeded |
99 |
Execution timed out |
1074 ms |
98568 KB |
Time limit exceeded |
100 |
Execution timed out |
1082 ms |
98564 KB |
Time limit exceeded |