답안 #973315

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
973315 2024-05-01T18:22:25 Z MilosMilutinovic Bomb (IZhO17_bomb) C++14
5 / 100
132 ms 87220 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;
    }
  }
  vector<int> mx(m + 1, n);
  for (int i = 0; i < n; i++) {
    vector<int> stk;
    for (int j = 0; j < m; j++) {
      if (s[i][j] == '0') {
        while (!stk.empty()) {
          int l = j - stk.back();
          mx[l] = min(mx[l], len[i][stk.back()]);
          stk.pop_back();
        }
        continue;
      }
      while (!stk.empty() && len[i][stk.back()] >= len[i][j]) {
        int l = j - stk.back() + 1;
        mx[l] = min(mx[l], len[i][j]);
        stk.pop_back();
      }
      if (!stk.empty()) {
        int l = j - stk.back() + 1;
        mx[l] = min(mx[l], len[i][stk.back()]);
      }
      stk.push_back(j);
    }
    while (!stk.empty()) {
      int l = m - stk.back();
      mx[l] = min(mx[l], len[i][stk.back()]);
      stk.pop_back();
    }
  }
  for (int i = 0; i < n; i++) {
    vector<int> stk;
    for (int j = m - 1; j >= 0; j--) {
      if (s[i][j] == '0') {
        while (!stk.empty()) {
          int l = stk.back() - j;
          mx[l] = min(mx[l], len[i][stk.back()]);
          stk.pop_back();
        }
        continue;
      }
      while (!stk.empty() && len[i][stk.back()] >= len[i][j]) {
        int l = stk.back() - j + 1;
        mx[l] = min(mx[l], len[i][j]);
        stk.pop_back();
      }
      if (!stk.empty()) {
        int l = stk.back() - j + 1;
        mx[l] = min(mx[l], len[i][stk.back()]);
      }
      stk.push_back(j);
    }
    while (!stk.empty()) {
      int l = stk.back() + 1;
      mx[l] = min(mx[l], len[i][stk.back()]);
      stk.pop_back();
    }
  }
  for (int i = 1; i < m; i++) {
    mx[i + 1] = min(mx[i + 1], mx[i]);
  }
  int res = n * m;
  for (int i = 1; i <= m; i++) {
    res = min(res, mx[i] * i);
  }
  cout << res << '\n';
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 500 KB Output isn't 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 Incorrect 0 ms 348 KB Output isn't correct
6 Incorrect 0 ms 348 KB Output isn't correct
7 Correct 0 ms 348 KB Output is correct
8 Incorrect 0 ms 348 KB Output isn't correct
9 Incorrect 0 ms 348 KB Output isn't correct
10 Incorrect 1 ms 348 KB Output isn't correct
11 Incorrect 0 ms 348 KB Output isn't correct
12 Correct 0 ms 456 KB Output is correct
13 Incorrect 0 ms 348 KB Output isn't correct
14 Incorrect 0 ms 348 KB Output isn't correct
15 Incorrect 1 ms 348 KB Output isn't correct
16 Incorrect 0 ms 348 KB Output isn't correct
17 Incorrect 1 ms 348 KB Output isn't correct
18 Incorrect 1 ms 348 KB Output isn't correct
19 Incorrect 1 ms 348 KB Output isn't correct
20 Incorrect 1 ms 344 KB Output isn't correct
21 Incorrect 0 ms 344 KB Output isn't correct
22 Incorrect 0 ms 348 KB Output isn't correct
23 Incorrect 1 ms 600 KB Output isn't correct
24 Incorrect 1 ms 348 KB Output isn't correct
25 Incorrect 1 ms 600 KB Output isn't correct
26 Incorrect 1 ms 604 KB Output isn't correct
27 Incorrect 2 ms 1372 KB Output isn't correct
28 Incorrect 2 ms 1888 KB Output isn't correct
29 Incorrect 3 ms 2140 KB Output isn't correct
30 Incorrect 3 ms 2908 KB Output isn't correct
31 Incorrect 3 ms 2396 KB Output isn't correct
32 Incorrect 3 ms 2652 KB Output isn't correct
33 Incorrect 3 ms 3164 KB Output isn't correct
34 Incorrect 2 ms 1628 KB Output isn't correct
35 Incorrect 3 ms 3092 KB Output isn't correct
36 Incorrect 5 ms 3164 KB Output isn't correct
37 Incorrect 0 ms 344 KB Output isn't correct
38 Incorrect 113 ms 86960 KB Output isn't correct
39 Incorrect 0 ms 348 KB Output isn't correct
40 Incorrect 15 ms 11100 KB Output isn't correct
41 Incorrect 0 ms 348 KB Output isn't correct
42 Incorrect 1 ms 604 KB Output isn't correct
43 Incorrect 118 ms 86740 KB Output isn't correct
44 Incorrect 4 ms 3348 KB Output isn't correct
45 Incorrect 108 ms 86856 KB Output isn't correct
46 Incorrect 100 ms 86972 KB Output isn't correct
47 Incorrect 107 ms 86944 KB Output isn't correct
48 Incorrect 106 ms 87220 KB Output isn't correct
49 Incorrect 132 ms 87120 KB Output isn't correct
50 Incorrect 106 ms 86976 KB Output isn't correct
51 Incorrect 104 ms 86864 KB Output isn't correct
52 Incorrect 104 ms 86940 KB Output isn't correct
53 Incorrect 106 ms 86932 KB Output isn't correct
54 Incorrect 95 ms 86976 KB Output isn't correct
55 Incorrect 115 ms 86868 KB Output isn't correct
56 Incorrect 112 ms 86736 KB Output isn't correct
57 Incorrect 95 ms 86868 KB Output isn't correct
58 Incorrect 95 ms 86944 KB Output isn't correct
59 Incorrect 97 ms 86732 KB Output isn't correct
60 Incorrect 106 ms 87000 KB Output isn't correct
61 Incorrect 123 ms 86832 KB Output isn't correct
62 Incorrect 112 ms 86868 KB Output isn't correct
63 Incorrect 123 ms 86968 KB Output isn't correct
64 Incorrect 93 ms 86740 KB Output isn't correct
65 Incorrect 103 ms 87052 KB Output isn't correct
66 Incorrect 119 ms 86972 KB Output isn't correct
67 Incorrect 109 ms 86816 KB Output isn't correct
68 Incorrect 111 ms 86980 KB Output isn't correct
69 Incorrect 95 ms 86948 KB Output isn't correct
70 Incorrect 55 ms 55636 KB Output isn't correct
71 Incorrect 89 ms 86868 KB Output isn't correct
72 Incorrect 93 ms 86972 KB Output isn't correct
73 Incorrect 104 ms 86968 KB Output isn't correct
74 Incorrect 96 ms 86972 KB Output isn't correct
75 Incorrect 93 ms 86972 KB Output isn't correct
76 Incorrect 94 ms 86976 KB Output isn't correct
77 Incorrect 98 ms 86868 KB Output isn't correct
78 Incorrect 93 ms 86868 KB Output isn't correct
79 Incorrect 83 ms 86892 KB Output isn't correct
80 Incorrect 88 ms 86764 KB Output isn't correct
81 Incorrect 85 ms 86880 KB Output isn't correct
82 Incorrect 105 ms 86856 KB Output isn't correct
83 Incorrect 101 ms 86864 KB Output isn't correct
84 Incorrect 83 ms 86868 KB Output isn't correct
85 Incorrect 94 ms 87120 KB Output isn't correct
86 Incorrect 106 ms 86864 KB Output isn't correct
87 Incorrect 91 ms 86864 KB Output isn't correct
88 Incorrect 99 ms 86868 KB Output isn't correct
89 Incorrect 105 ms 87000 KB Output isn't correct
90 Incorrect 58 ms 55632 KB Output isn't correct
91 Incorrect 96 ms 86964 KB Output isn't correct
92 Incorrect 98 ms 86968 KB Output isn't correct
93 Incorrect 112 ms 86732 KB Output isn't correct
94 Incorrect 100 ms 86868 KB Output isn't correct
95 Incorrect 98 ms 86948 KB Output isn't correct
96 Incorrect 99 ms 87156 KB Output isn't correct
97 Incorrect 108 ms 86976 KB Output isn't correct
98 Incorrect 98 ms 86956 KB Output isn't correct
99 Incorrect 96 ms 86972 KB Output isn't correct
100 Incorrect 109 ms 86868 KB Output isn't correct