답안 #404583

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
404583 2021-05-14T16:55:05 Z rama_pang Bomb (IZhO17_bomb) C++17
90 / 100
442 ms 74348 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, 1e9);
  for (int rep = 0; rep < 2; rep++) { // for prefix, then suffix
    for (int i = 1; i <= N; i++) {
      for (int j = 1; j <= M; j++) if (A[i][j]) {
        int jj = j;
        while (jj + 1 <= M && A[i][jj + 1]) jj += 1;

        int len = jj - j + 1;
        int minUp = 1e9;
        int minDn = 1e9;
        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[0] = min(ans[0], up[i][j] + dn[i][j] - 1);
        ans[len + 1] = 0;
        j = jj;
      }
    }
    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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 2 ms 456 KB Output is correct
3 Correct 15 ms 30396 KB Output is correct
4 Correct 16 ms 30396 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Incorrect 1 ms 332 KB Output isn't correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 448 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 1 ms 452 KB Output is correct
16 Correct 1 ms 460 KB Output is correct
17 Correct 1 ms 1096 KB Output is correct
18 Correct 1 ms 1228 KB Output is correct
19 Correct 2 ms 1484 KB Output is correct
20 Correct 2 ms 1484 KB Output is correct
21 Correct 1 ms 972 KB Output is correct
22 Correct 2 ms 1228 KB Output is correct
23 Correct 2 ms 1612 KB Output is correct
24 Correct 2 ms 1348 KB Output is correct
25 Correct 2 ms 1612 KB Output is correct
26 Incorrect 2 ms 1608 KB Output isn't correct
27 Incorrect 6 ms 4888 KB Output isn't correct
28 Correct 6 ms 5196 KB Output is correct
29 Correct 8 ms 6604 KB Output is correct
30 Correct 10 ms 7812 KB Output is correct
31 Correct 8 ms 6216 KB Output is correct
32 Correct 8 ms 7116 KB Output is correct
33 Correct 11 ms 8256 KB Output is correct
34 Correct 6 ms 5580 KB Output is correct
35 Correct 11 ms 8256 KB Output is correct
36 Incorrect 14 ms 8264 KB Output isn't correct
37 Correct 1 ms 460 KB Output is correct
38 Correct 440 ms 74052 KB Output is correct
39 Correct 1 ms 460 KB Output is correct
40 Correct 65 ms 20036 KB Output is correct
41 Correct 1 ms 460 KB Output is correct
42 Correct 2 ms 1612 KB Output is correct
43 Correct 383 ms 74036 KB Output is correct
44 Correct 11 ms 8232 KB Output is correct
45 Correct 372 ms 73972 KB Output is correct
46 Correct 369 ms 74184 KB Output is correct
47 Correct 374 ms 74084 KB Output is correct
48 Correct 360 ms 74116 KB Output is correct
49 Incorrect 431 ms 73952 KB Output isn't correct
50 Correct 387 ms 74016 KB Output is correct
51 Correct 363 ms 73860 KB Output is correct
52 Correct 367 ms 73904 KB Output is correct
53 Correct 361 ms 73948 KB Output is correct
54 Correct 332 ms 73904 KB Output is correct
55 Correct 310 ms 73988 KB Output is correct
56 Correct 435 ms 74104 KB Output is correct
57 Correct 310 ms 74052 KB Output is correct
58 Correct 313 ms 74044 KB Output is correct
59 Correct 317 ms 74072 KB Output is correct
60 Incorrect 351 ms 74092 KB Output isn't correct
61 Incorrect 433 ms 74348 KB Output isn't correct
62 Incorrect 442 ms 73924 KB Output isn't correct
63 Incorrect 431 ms 74024 KB Output isn't correct
64 Incorrect 308 ms 73976 KB Output isn't correct
65 Correct 367 ms 73920 KB Output is correct
66 Correct 353 ms 73936 KB Output is correct
67 Correct 382 ms 73884 KB Output is correct
68 Correct 377 ms 74124 KB Output is correct
69 Correct 308 ms 74092 KB Output is correct
70 Correct 183 ms 59252 KB Output is correct
71 Correct 286 ms 73996 KB Output is correct
72 Correct 303 ms 74076 KB Output is correct
73 Correct 339 ms 73984 KB Output is correct
74 Correct 366 ms 73988 KB Output is correct
75 Correct 306 ms 74064 KB Output is correct
76 Correct 329 ms 74140 KB Output is correct
77 Correct 314 ms 73928 KB Output is correct
78 Correct 312 ms 74048 KB Output is correct
79 Correct 261 ms 73924 KB Output is correct
80 Correct 261 ms 73928 KB Output is correct
81 Correct 272 ms 74112 KB Output is correct
82 Correct 345 ms 74104 KB Output is correct
83 Correct 319 ms 74236 KB Output is correct
84 Correct 260 ms 74016 KB Output is correct
85 Correct 311 ms 74208 KB Output is correct
86 Correct 442 ms 74004 KB Output is correct
87 Correct 310 ms 74168 KB Output is correct
88 Correct 317 ms 74012 KB Output is correct
89 Correct 347 ms 73924 KB Output is correct
90 Correct 199 ms 59204 KB Output is correct
91 Correct 355 ms 73980 KB Output is correct
92 Correct 355 ms 73996 KB Output is correct
93 Correct 413 ms 73920 KB Output is correct
94 Correct 361 ms 73968 KB Output is correct
95 Correct 312 ms 73884 KB Output is correct
96 Correct 326 ms 74008 KB Output is correct
97 Correct 421 ms 74168 KB Output is correct
98 Correct 313 ms 74128 KB Output is correct
99 Correct 372 ms 74148 KB Output is correct
100 Correct 415 ms 74016 KB Output is correct