제출 #1354576

#제출 시각아이디문제언어결과실행 시간메모리
1354576thewizardman호화 벙커 (IZhO13_burrow)C++20
100 / 100
482 ms39636 KiB
#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
#define ms(x, y) memset(x, y, sizeof x)
#define sp ,' ',
#define el ,'\n'
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using l2 = array<ll, 2>;
using l3 = array<ll, 3>;

template<typename... Args>
inline void out(Args... args) {
  (cout << ... << args);
}

struct hi {
  template<typename T>
  inline hi& operator,(T& x) {
    cin >> x;
    return *this;
  }
} in;
#define in in,

int n, m, k, h[1000][1000], l[1000][1000], lo, hi, mid, ans, ansarea, sz = 0, st[1000][2];
vector<l3> v;
vector<int> compress;

void solve() {
  in n, m, k;
  for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) {
    int x; in x;
    v.push_back({x, i, j});
    compress.push_back(x);
  }
  sort(v.begin(), v.end(), greater<>());
  sort(compress.begin(), compress.end());
  compress.resize(unique(compress.begin(), compress.end()) - compress.begin());
  for (auto &[x, i, j]: v) x = lower_bound(compress.begin(), compress.end(), x) - compress.begin();
  hi = compress.size() - 1;
  while (lo <= hi) {
    ms(h, 0);
    ms(l, 0);
    mid = (lo + hi) >> 1;
    int area = 0;
    for (auto [x, i, j]: v) {
      if (x < mid) break;
      h[i][j] = 1;
    }
    // out(mid el);
    for (int i = 1; i < n; i++) for (int j = 0; j < m; j++) if (h[i-1][j] && h[i][j]) h[i][j] += h[i-1][j];
    // for (int i = 0; i < n; i++) {for (int j = 0; j < m; j++) out(h[i][j], ' '); out('\n');}
    for (int i = 0; i < n; i++) {
      sz = 0;
      for (int j = 0; j < m; j++) {
        while (sz && st[sz-1][0] >= h[i][j]) --sz;
        if (sz == 0) l[i][j] = -1;
        else l[i][j] = st[sz-1][1];
        st[sz][0] = h[i][j];
        st[sz++][1] = j;
      }
      sz = 0;
      for (int j = m-1; j >= 0; j--) {
        while (sz && st[sz-1][0] >= h[i][j]) --sz;
        int r = m;
        if (sz) r = st[sz-1][1];
        st[sz][0] = h[i][j];
        st[sz++][1] = j;
        area = max(area, (r-l[i][j]-1) * h[i][j]);
      }
    }
    // for (int i = 0; i < n; i++) {for (int j = 0; j < m; j++) out(l[i][j], ' '); out('\n');}
    // out('\n');
    if (area >= k) ans = mid, ansarea = area, lo = mid + 1;
    else hi = mid - 1;
  }
  out(compress[ans] sp ansarea el);
}

signed main() {
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  int t = 1;
  // in(t);
  while (t--) solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...