답안 #973319

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
973319 2024-05-01T18:26:25 Z MilosMilutinovic Bomb (IZhO17_bomb) C++14
0 / 100
1 ms 604 KB
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  assert(n == 1);
  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 0 ms 344 KB Output isn't correct
2 Runtime error 1 ms 600 KB Execution killed with signal 6
3 Runtime error 1 ms 604 KB Execution killed with signal 6
4 Runtime error 1 ms 604 KB Execution killed with signal 6
5 Incorrect 0 ms 348 KB Output isn't correct
6 Incorrect 1 ms 348 KB Output isn't correct
7 Runtime error 1 ms 604 KB Execution killed with signal 6
8 Runtime error 1 ms 604 KB Execution killed with signal 6
9 Runtime error 1 ms 604 KB Execution killed with signal 6
10 Runtime error 1 ms 604 KB Execution killed with signal 6
11 Runtime error 1 ms 604 KB Execution killed with signal 6
12 Runtime error 1 ms 604 KB Execution killed with signal 6
13 Runtime error 1 ms 604 KB Execution killed with signal 6
14 Runtime error 1 ms 604 KB Execution killed with signal 6
15 Runtime error 1 ms 604 KB Execution killed with signal 6
16 Runtime error 1 ms 604 KB Execution killed with signal 6
17 Runtime error 1 ms 604 KB Execution killed with signal 6
18 Runtime error 1 ms 604 KB Execution killed with signal 6
19 Runtime error 1 ms 604 KB Execution killed with signal 6
20 Runtime error 1 ms 604 KB Execution killed with signal 6
21 Runtime error 1 ms 604 KB Execution killed with signal 6
22 Runtime error 1 ms 604 KB Execution killed with signal 6
23 Runtime error 1 ms 604 KB Execution killed with signal 6
24 Runtime error 1 ms 604 KB Execution killed with signal 6
25 Runtime error 1 ms 604 KB Execution killed with signal 6
26 Runtime error 1 ms 604 KB Execution killed with signal 6
27 Runtime error 1 ms 604 KB Execution killed with signal 6
28 Runtime error 1 ms 604 KB Execution killed with signal 6
29 Runtime error 1 ms 604 KB Execution killed with signal 6
30 Runtime error 1 ms 604 KB Execution killed with signal 6
31 Runtime error 1 ms 604 KB Execution killed with signal 6
32 Runtime error 1 ms 604 KB Execution killed with signal 6
33 Runtime error 1 ms 604 KB Execution killed with signal 6
34 Runtime error 1 ms 604 KB Execution killed with signal 6
35 Runtime error 1 ms 604 KB Execution killed with signal 6
36 Runtime error 1 ms 604 KB Execution killed with signal 6
37 Runtime error 1 ms 604 KB Execution killed with signal 6
38 Runtime error 1 ms 604 KB Execution killed with signal 6
39 Runtime error 1 ms 604 KB Execution killed with signal 6
40 Runtime error 1 ms 604 KB Execution killed with signal 6
41 Runtime error 1 ms 604 KB Execution killed with signal 6
42 Runtime error 1 ms 600 KB Execution killed with signal 6
43 Runtime error 1 ms 604 KB Execution killed with signal 6
44 Runtime error 1 ms 604 KB Execution killed with signal 6
45 Runtime error 1 ms 604 KB Execution killed with signal 6
46 Runtime error 1 ms 604 KB Execution killed with signal 6
47 Runtime error 1 ms 600 KB Execution killed with signal 6
48 Runtime error 1 ms 604 KB Execution killed with signal 6
49 Runtime error 1 ms 604 KB Execution killed with signal 6
50 Runtime error 1 ms 604 KB Execution killed with signal 6
51 Runtime error 1 ms 604 KB Execution killed with signal 6
52 Runtime error 1 ms 604 KB Execution killed with signal 6
53 Runtime error 1 ms 604 KB Execution killed with signal 6
54 Runtime error 1 ms 604 KB Execution killed with signal 6
55 Runtime error 1 ms 604 KB Execution killed with signal 6
56 Runtime error 1 ms 604 KB Execution killed with signal 6
57 Runtime error 1 ms 604 KB Execution killed with signal 6
58 Runtime error 1 ms 604 KB Execution killed with signal 6
59 Runtime error 1 ms 604 KB Execution killed with signal 6
60 Runtime error 1 ms 604 KB Execution killed with signal 6
61 Runtime error 1 ms 604 KB Execution killed with signal 6
62 Runtime error 1 ms 604 KB Execution killed with signal 6
63 Runtime error 1 ms 604 KB Execution killed with signal 6
64 Runtime error 1 ms 600 KB Execution killed with signal 6
65 Runtime error 1 ms 604 KB Execution killed with signal 6
66 Runtime error 1 ms 604 KB Execution killed with signal 6
67 Runtime error 1 ms 604 KB Execution killed with signal 6
68 Runtime error 1 ms 604 KB Execution killed with signal 6
69 Runtime error 1 ms 604 KB Execution killed with signal 6
70 Runtime error 1 ms 604 KB Execution killed with signal 6
71 Runtime error 1 ms 604 KB Execution killed with signal 6
72 Runtime error 1 ms 604 KB Execution killed with signal 6
73 Runtime error 1 ms 604 KB Execution killed with signal 6
74 Runtime error 1 ms 604 KB Execution killed with signal 6
75 Runtime error 1 ms 604 KB Execution killed with signal 6
76 Runtime error 1 ms 604 KB Execution killed with signal 6
77 Runtime error 1 ms 604 KB Execution killed with signal 6
78 Runtime error 1 ms 604 KB Execution killed with signal 6
79 Runtime error 1 ms 604 KB Execution killed with signal 6
80 Runtime error 1 ms 600 KB Execution killed with signal 6
81 Runtime error 1 ms 604 KB Execution killed with signal 6
82 Runtime error 1 ms 604 KB Execution killed with signal 6
83 Runtime error 1 ms 604 KB Execution killed with signal 6
84 Runtime error 1 ms 604 KB Execution killed with signal 6
85 Runtime error 1 ms 604 KB Execution killed with signal 6
86 Runtime error 1 ms 600 KB Execution killed with signal 6
87 Runtime error 1 ms 604 KB Execution killed with signal 6
88 Runtime error 1 ms 604 KB Execution killed with signal 6
89 Runtime error 1 ms 604 KB Execution killed with signal 6
90 Runtime error 1 ms 604 KB Execution killed with signal 6
91 Runtime error 1 ms 604 KB Execution killed with signal 6
92 Runtime error 1 ms 604 KB Execution killed with signal 6
93 Runtime error 1 ms 604 KB Execution killed with signal 6
94 Runtime error 1 ms 604 KB Execution killed with signal 6
95 Runtime error 1 ms 604 KB Execution killed with signal 6
96 Runtime error 1 ms 604 KB Execution killed with signal 6
97 Runtime error 1 ms 604 KB Execution killed with signal 6
98 Runtime error 1 ms 604 KB Execution killed with signal 6
99 Runtime error 1 ms 600 KB Execution killed with signal 6
100 Runtime error 1 ms 604 KB Execution killed with signal 6