Submission #973332

# Submission time Handle Problem Language Result Execution time Memory
973332 2024-05-01T18:44:32 Z MilosMilutinovic Bomb (IZhO17_bomb) C++14
24 / 100
102 ms 80960 KB
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<string> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  vector<vector<int>> U(n, vector<int>(m));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (s[i][j] == '0') {
        continue; 
      }
      U[i][j] = (i == 0 || s[i - 1][j] == '0' ? i : U[i - 1][j]);
    }
  }
  vector<vector<int>> D(n, vector<int>(m));
  for (int i = n - 1; i >= 0; i--) {
    for (int j = 0; j < m; j++) {
      if (s[i][j] == '0') {
        continue;
      }
      D[i][j] = (i == n - 1 || s[i + 1][j] == '0' ? i : D[i + 1][j]);
    }
  }
  vector<vector<int>> len(n, vector<int>(m));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (s[i][j] == '0') {
        continue;
      }
      len[i][j] = D[i][j] - U[i][j] + 1;
    }
  }
  int width = m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (s[i][j] == '0') {
        continue;
      }
      int ptr = j;
      while (ptr + 1 < m && s[i][ptr + 1] == '1') {
        ptr += 1;
      }
      width = min(width, ptr - j + 1);
      j = ptr;
    }
  }
  int height = n;
  for (int j = 0; j < m; j++) {
    for (int i = 0; i < n; i++) {
      if (s[i][j] == '0') {
        continue;
      }
      int ptr = i;
      while (ptr + 1 < n && s[ptr + 1][j] == '1') {
        ptr += 1;
      }
      height = min(height, ptr - i + 1);
      i = ptr;
    }
  }
  vector<int> mx(m + 1, height);
  for (int i = 0; i < n; i++) {
    int bef = -1;
    int val = (int) 1e9;
    for (int j = 0; j < m; j++) {
      if (s[i][j] == '0') {
        bef = j;
        val = (int) 1e9;
        continue;
      }
      val = min(val, len[i][j]);
      mx[j - bef] = min(mx[j - bef], val);
    }
  }
  for (int i = 0; i < n; i++) {
    int bef = m;
    int val = (int) 1e9;
    for (int j = m - 1; j >= 0; j--) {
      if (s[i][j] == '0') {
        bef = j;
        val = (int) 1e9;
        continue;
      }
      val = min(val, len[i][j]);
      mx[bef - j] = min(mx[bef - j], val);
    }
  }
  for (int i = 1; i < width; i++) {
    mx[i + 1] = min(mx[i + 1], mx[i]);
  }
  int res = 0;
  for (int i = 1; i <= width; i++) {
    res = max(res, mx[i] * i);
  }
  cout << res << '\n';
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Incorrect 0 ms 348 KB Output isn't correct
9 Incorrect 1 ms 348 KB Output isn't correct
10 Incorrect 1 ms 348 KB Output isn't correct
11 Incorrect 1 ms 348 KB Output isn't correct
12 Incorrect 1 ms 344 KB Output isn't correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Incorrect 0 ms 348 KB Output isn't correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Incorrect 0 ms 348 KB Output isn't correct
19 Incorrect 0 ms 348 KB Output isn't correct
20 Incorrect 0 ms 348 KB Output isn't correct
21 Incorrect 0 ms 348 KB Output isn't correct
22 Incorrect 1 ms 344 KB Output isn't correct
23 Incorrect 1 ms 348 KB Output isn't correct
24 Incorrect 0 ms 348 KB Output isn't correct
25 Incorrect 1 ms 348 KB Output isn't correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 2 ms 1368 KB Output is correct
28 Incorrect 2 ms 1880 KB Output isn't correct
29 Incorrect 2 ms 1880 KB Output isn't correct
30 Incorrect 4 ms 2904 KB Output isn't correct
31 Incorrect 2 ms 2392 KB Output isn't correct
32 Incorrect 2 ms 2396 KB Output isn't correct
33 Incorrect 4 ms 2908 KB Output isn't correct
34 Incorrect 1 ms 1372 KB Output isn't correct
35 Incorrect 2 ms 2904 KB Output isn't correct
36 Correct 4 ms 2904 KB Output is correct
37 Incorrect 0 ms 600 KB Output isn't correct
38 Correct 98 ms 80720 KB Output is correct
39 Incorrect 1 ms 348 KB Output isn't correct
40 Incorrect 12 ms 10252 KB Output isn't correct
41 Incorrect 1 ms 348 KB Output isn't correct
42 Incorrect 0 ms 604 KB Output isn't correct
43 Correct 87 ms 80624 KB Output is correct
44 Incorrect 3 ms 2908 KB Output isn't correct
45 Incorrect 89 ms 80840 KB Output isn't correct
46 Correct 85 ms 80636 KB Output is correct
47 Incorrect 86 ms 80608 KB Output isn't correct
48 Incorrect 87 ms 80724 KB Output isn't correct
49 Correct 95 ms 80736 KB Output is correct
50 Incorrect 89 ms 80720 KB Output isn't correct
51 Incorrect 91 ms 80720 KB Output isn't correct
52 Incorrect 88 ms 80600 KB Output isn't correct
53 Incorrect 89 ms 80724 KB Output isn't correct
54 Incorrect 86 ms 80840 KB Output isn't correct
55 Incorrect 81 ms 80724 KB Output isn't correct
56 Correct 92 ms 80832 KB Output is correct
57 Incorrect 83 ms 80824 KB Output isn't correct
58 Incorrect 80 ms 80724 KB Output isn't correct
59 Incorrect 79 ms 80720 KB Output isn't correct
60 Correct 86 ms 80848 KB Output is correct
61 Correct 94 ms 80840 KB Output is correct
62 Correct 94 ms 80656 KB Output is correct
63 Correct 102 ms 80844 KB Output is correct
64 Correct 85 ms 80840 KB Output is correct
65 Incorrect 88 ms 80720 KB Output isn't correct
66 Incorrect 87 ms 80720 KB Output isn't correct
67 Incorrect 87 ms 80720 KB Output isn't correct
68 Incorrect 89 ms 80720 KB Output isn't correct
69 Incorrect 81 ms 80848 KB Output isn't correct
70 Incorrect 46 ms 51920 KB Output isn't correct
71 Incorrect 75 ms 80840 KB Output isn't correct
72 Incorrect 82 ms 80652 KB Output isn't correct
73 Incorrect 86 ms 80736 KB Output isn't correct
74 Incorrect 84 ms 80728 KB Output isn't correct
75 Incorrect 80 ms 80844 KB Output isn't correct
76 Incorrect 95 ms 80844 KB Output isn't correct
77 Incorrect 85 ms 80684 KB Output isn't correct
78 Incorrect 81 ms 80724 KB Output isn't correct
79 Incorrect 77 ms 80720 KB Output isn't correct
80 Incorrect 71 ms 80724 KB Output isn't correct
81 Incorrect 85 ms 80748 KB Output isn't correct
82 Incorrect 90 ms 80848 KB Output isn't correct
83 Incorrect 82 ms 80832 KB Output isn't correct
84 Incorrect 74 ms 80724 KB Output isn't correct
85 Incorrect 83 ms 80720 KB Output isn't correct
86 Incorrect 93 ms 80720 KB Output isn't correct
87 Incorrect 81 ms 80760 KB Output isn't correct
88 Incorrect 82 ms 80840 KB Output isn't correct
89 Incorrect 86 ms 80724 KB Output isn't correct
90 Incorrect 63 ms 51816 KB Output isn't correct
91 Incorrect 91 ms 80960 KB Output isn't correct
92 Incorrect 86 ms 80852 KB Output isn't correct
93 Incorrect 92 ms 80720 KB Output isn't correct
94 Incorrect 84 ms 80680 KB Output isn't correct
95 Incorrect 80 ms 80632 KB Output isn't correct
96 Incorrect 91 ms 80904 KB Output isn't correct
97 Incorrect 93 ms 80848 KB Output isn't correct
98 Incorrect 87 ms 80720 KB Output isn't correct
99 Incorrect 84 ms 80844 KB Output isn't correct
100 Incorrect 92 ms 80844 KB Output isn't correct