Submission #526479

# Submission time Handle Problem Language Result Execution time Memory
526479 2022-02-14T23:46:26 Z TheKingAleks Bomb (IZhO17_bomb) C++14
52 / 100
352 ms 80096 KB
#include <bits/stdc++.h>
using namespace std;
 
int N, M;
int A[2505][2505];
int up[2505][2505];
int dn[2505][2505];
 
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
 
  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 - '0';
    }
  }
 
  // Solution:
  //
  // The upper bound on height and width is the minimum length
  // vertical and horizontal strip. Now, for a fixed width Y,
  // we want to determine the maximum height X. Note that,
  // if we have width Y, then for every maximal horizontal
  // strip, height is bounded by the minimum (top - bottom)
  // of the prefix and suffix of size Y.
  //
  // We only need to consider the prefix and suffix. Why?
  // For, after a prefix of size Y, let's move it to the right.
  // If the (top - bottom) decreased, that means that there is
  // a vertical strip which is shifted downwards, which means
  // it will occcupy a maximal horizontal strip -> we will compute
  // it later.
  //
  // Time complexity: O(N M).
 
  for (int j = 1; j <= M; j++) {
    for (int i = 1; i <= N; i++) {
      if (A[i][j]) {
        up[i][j] = 1 + up[i - 1][j];
      }
    }
    for (int i = N; i >= 1; i--) {
      if (A[i][j]) {
        dn[i][j] = 1 + dn[i + 1][j];
      }
    }
  }
 
  vector<int> ans(M + 2, N);
  for (int rep = 0; rep < 1; rep++) { // for prefix, then suffix
    for (int i = 1; i <= N; i++) {
      for (int j = 1; j <= M; j++) if (A[i][j]) {
        ans[1] = min(ans[1], up[i][j] + dn[i][j] - 1);
      }
      for (int j = 1; j <= M; j++) if (A[i][j] && !A[i][j - 1]) {
        int jj = j;
        while (A[i][jj + 1]) jj += 1;
 
        int len = jj - j + 1;
        int minUp = N;
        int minDn = N;
        for (int k = 1; k <= len; k++) {
          minUp = min(minUp, up[i][j + k - 1]);
          minDn = min(minDn, dn[i][j + k - 1]);
          ans[k] = min(ans[k], minUp + minDn - 1);
        }
 
        ans[len + 1] = 0;
      }
    }
    for (int i = 1; i <= N; i++) {
      for (int j = 1; j + j <= M; j++) {
        swap(A[i][j], A[i][M - j + 1]);
        swap(up[i][j], up[i][M - j + 1]);
        swap(dn[i][j], dn[i][M - j + 1]);
      }
    }
  }
 
  int answer = 0;
  for (int i = 1; i <= M; i++) {
    ans[i] = min(ans[i], ans[i - 1]);
    answer = max(answer, i * ans[i]);
  }
 
  cout << answer << '\n';
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 10 ms 30412 KB Output is correct
4 Correct 11 ms 30424 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Incorrect 1 ms 548 KB Output isn't correct
9 Incorrect 1 ms 576 KB Output isn't correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Incorrect 1 ms 444 KB Output isn't correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Incorrect 0 ms 448 KB Output isn't correct
16 Correct 1 ms 460 KB Output is correct
17 Correct 1 ms 1100 KB Output is correct
18 Correct 1 ms 1140 KB Output is correct
19 Incorrect 1 ms 1484 KB Output isn't correct
20 Incorrect 1 ms 1484 KB Output isn't correct
21 Correct 1 ms 972 KB Output is correct
22 Correct 1 ms 1228 KB Output is correct
23 Incorrect 1 ms 1612 KB Output isn't correct
24 Incorrect 1 ms 1356 KB Output isn't correct
25 Incorrect 1 ms 1612 KB Output isn't correct
26 Correct 1 ms 1612 KB Output is correct
27 Correct 5 ms 4800 KB Output is correct
28 Incorrect 5 ms 5196 KB Output isn't correct
29 Incorrect 7 ms 6508 KB Output isn't correct
30 Incorrect 7 ms 7884 KB Output isn't correct
31 Correct 6 ms 6144 KB Output is correct
32 Incorrect 6 ms 7112 KB Output isn't correct
33 Incorrect 8 ms 8260 KB Output isn't correct
34 Incorrect 4 ms 5576 KB Output isn't correct
35 Incorrect 8 ms 8224 KB Output isn't correct
36 Correct 9 ms 8284 KB Output is correct
37 Incorrect 0 ms 580 KB Output isn't correct
38 Correct 308 ms 79968 KB Output is correct
39 Incorrect 1 ms 460 KB Output isn't correct
40 Correct 44 ms 20584 KB Output is correct
41 Correct 1 ms 464 KB Output is correct
42 Correct 1 ms 1612 KB Output is correct
43 Correct 287 ms 79988 KB Output is correct
44 Correct 9 ms 8260 KB Output is correct
45 Incorrect 291 ms 79920 KB Output isn't correct
46 Correct 260 ms 79972 KB Output is correct
47 Incorrect 268 ms 79968 KB Output isn't correct
48 Correct 256 ms 79984 KB Output is correct
49 Correct 342 ms 79908 KB Output is correct
50 Correct 261 ms 80036 KB Output is correct
51 Correct 273 ms 79980 KB Output is correct
52 Correct 253 ms 79944 KB Output is correct
53 Correct 284 ms 79976 KB Output is correct
54 Correct 234 ms 80016 KB Output is correct
55 Incorrect 226 ms 79976 KB Output isn't correct
56 Correct 324 ms 79940 KB Output is correct
57 Incorrect 216 ms 79940 KB Output isn't correct
58 Correct 234 ms 79940 KB Output is correct
59 Correct 225 ms 79952 KB Output is correct
60 Correct 255 ms 79952 KB Output is correct
61 Correct 350 ms 79944 KB Output is correct
62 Correct 312 ms 79940 KB Output is correct
63 Correct 352 ms 79988 KB Output is correct
64 Correct 261 ms 79940 KB Output is correct
65 Correct 244 ms 79880 KB Output is correct
66 Correct 250 ms 79964 KB Output is correct
67 Correct 292 ms 80096 KB Output is correct
68 Correct 269 ms 79956 KB Output is correct
69 Correct 264 ms 80084 KB Output is correct
70 Incorrect 126 ms 63044 KB Output isn't correct
71 Incorrect 208 ms 79964 KB Output isn't correct
72 Incorrect 212 ms 79932 KB Output isn't correct
73 Correct 234 ms 79956 KB Output is correct
74 Incorrect 218 ms 79876 KB Output isn't correct
75 Incorrect 229 ms 80008 KB Output isn't correct
76 Incorrect 222 ms 79940 KB Output isn't correct
77 Incorrect 225 ms 80020 KB Output isn't correct
78 Incorrect 225 ms 79888 KB Output isn't correct
79 Incorrect 215 ms 79940 KB Output isn't correct
80 Incorrect 181 ms 80068 KB Output isn't correct
81 Incorrect 184 ms 79940 KB Output isn't correct
82 Incorrect 235 ms 80020 KB Output isn't correct
83 Incorrect 250 ms 79896 KB Output isn't correct
84 Incorrect 186 ms 79944 KB Output isn't correct
85 Incorrect 259 ms 79892 KB Output isn't correct
86 Incorrect 317 ms 80056 KB Output isn't correct
87 Incorrect 220 ms 79952 KB Output isn't correct
88 Correct 266 ms 79992 KB Output is correct
89 Correct 248 ms 79920 KB Output is correct
90 Incorrect 143 ms 63000 KB Output isn't correct
91 Incorrect 251 ms 79940 KB Output isn't correct
92 Incorrect 272 ms 79928 KB Output isn't correct
93 Incorrect 327 ms 79888 KB Output isn't correct
94 Correct 266 ms 79980 KB Output is correct
95 Incorrect 244 ms 79972 KB Output isn't correct
96 Correct 252 ms 79896 KB Output is correct
97 Incorrect 320 ms 79876 KB Output isn't correct
98 Incorrect 239 ms 79968 KB Output isn't correct
99 Incorrect 249 ms 79940 KB Output isn't correct
100 Incorrect 302 ms 79888 KB Output isn't correct