답안 #1092452

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1092452 2024-09-24T06:32:38 Z juicy 호화 벙커 (IZhO13_burrow) C++17
100 / 100
362 ms 17996 KB
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

const int N = 1005;

int n, m, k;
int a[N][N], up[N][N], l[N];

int qry(int md) {
  int area = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      up[i][j] = a[i][j] >= md ? up[i - 1][j] + 1 : 0;
    }
  }
  for (int i = 1; i <= n; ++i) {
    vector<int> st;
    for (int j = 1; j <= m; ++j) {
      while (st.size() && up[i][st.back()] >= up[i][j]) {
        st.pop_back();
      }
      l[j] = st.size() ? st.back() : 0;
      st.push_back(j);
    }
    vector<int>().swap(st);
    for (int j = m; j; --j) {
      while (st.size() && up[i][st.back()] >= up[i][j]) {
        st.pop_back();
      }
      int r = st.size() ? st.back() - 1 : m;
      area = max(area, up[i][j] * (r - l[j]));
      st.push_back(j);
    }
  }
  return area;
}

int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);

  cin >> n >> m >> k;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      cin >> a[i][j];
    }
  }
  int l = 1, r = 1e9, p = r;
  while (l <= r) {
    int md = (l + r) / 2;
    if (qry(md) >= k) {
      p = md;
      l = md + 1;
    } else {
      r = md - 1;
    }
  }
  cout << p << " " << qry(p);
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 7 ms 1116 KB Output is correct
9 Correct 6 ms 2012 KB Output is correct
10 Correct 19 ms 2228 KB Output is correct
11 Correct 28 ms 2904 KB Output is correct
12 Correct 18 ms 4440 KB Output is correct
13 Correct 25 ms 1616 KB Output is correct
14 Correct 58 ms 4056 KB Output is correct
15 Correct 54 ms 4128 KB Output is correct
16 Correct 53 ms 4436 KB Output is correct
17 Correct 62 ms 4700 KB Output is correct
18 Correct 131 ms 7956 KB Output is correct
19 Correct 185 ms 7804 KB Output is correct
20 Correct 327 ms 12112 KB Output is correct
21 Correct 307 ms 13780 KB Output is correct
22 Correct 360 ms 17996 KB Output is correct
23 Correct 362 ms 17756 KB Output is correct
24 Correct 278 ms 10588 KB Output is correct
25 Correct 279 ms 11092 KB Output is correct