Submission #36615861


Source Code Expand

// #define NDEBUG
#include <bits/stdc++.h>

#define REP_(i, a_, b_, a, b, ...) for (int i = (a), END_##i = (b); i < END_##i; ++i)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define ALL(x) std::begin(x), std::end(x)
using Int = long long;
using Uint = unsigned long long;
using Real = long double;

template<typename T, typename U>
inline bool chmax(T &a, U b) { return a < b and ((a = b), true); }
template<typename T, typename U>
inline bool chmin(T &a, U b) { return a > b and ((a = b), true); }
template<typename T>
constexpr T kBig = std::numeric_limits<T>::max() / 2;
#if __cplusplus < 202002L
template<typename T>
inline int ssize(const T &a) { return (int) a.size(); }
#endif

template<size_t BufSize>
class InputReader {
 public:
  void skip() {
    [[maybe_unused]] static const bool lazy_init = [this]() {
      const size_t len = fread(buf_, 1, sizeof(buf_) - 1, stdin);
      buf_[len] = '\0';
      ptr_ = buf_;
      bufend_ = buf_ + len;
      return true;
    }();
    while (isspace(*ptr_)) ++ptr_;
  }

  template<typename T>
  operator T() {
    T x;
    skip();
    assert(not is_eof());  // Couldn't read reached the end of input.
    read_one(x);
    return x;
  }

  struct Sized {
    InputReader<BufSize> &reader;
    int n;
    template<typename T>
    operator T() const {
      T xs(n);
      for (auto &x: xs) {
        reader.skip();
        assert(not reader.is_eof());
        reader.read_one(x);
      }
      return xs;
    }
  };
  Sized operator()(int n) { return {*this, n}; }

  bool is_eof() const { return ptr_ >= bufend_; }

 private:
  template<class T>
  std::enable_if_t<std::is_integral_v<T>> read_one(T &x) {
    [[maybe_unused]] int sign = 1;
    if constexpr (std::is_signed_v<T>) {
      sign = (*ptr_ == '-') ? (++ptr_, -1) : 1;
    }
    x = 0;
    while (isdigit(*ptr_)) x = x * 10 + (*ptr_++ & 0x0F);
    if constexpr (std::is_signed_v<T>) {
      x *= sign;
    }
  }
  void read_one(std::string &s) {
    char *p0 = ptr_;
    while (not isspace(*ptr_)) ptr_++;
    s.assign(p0, ptr_);
  }
  void read_one(std::string_view &s) {
    const char *p0 = ptr_;
    while (not isspace(*ptr_)) ptr_++;
    s = std::string_view(p0, ptr_ - p0);
  }

  static inline char buf_[BufSize];
  char *ptr_, *bufend_;
};
InputReader<(1 << 26)> in;

template<typename Container>
std::ostream &out_seq(const Container &seq, const char *sep = " ",
                      const char *ends = "\n", std::ostream &os = std::cout) {
  const auto itl = std::begin(seq), itr = std::end(seq);
  for (auto it = itl; it != itr; ++it) {
    if (it != itl) os << sep;
    os << *it;
  }
  return os << ends;
}

template<typename T>
std::ostream &out_one(const T &x, char endc) {
  if constexpr (std::is_same<T, bool>::value) {
    return std::cout << (x ? "Yes" : "No") << endc;
  } else {
    return std::cout << x << endc;
  }
}
template<typename T>
std::ostream &out(const T &x) {
  return out_one(x, '\n');
}
template<typename T, typename... Ts>
std::ostream &out(const T &head, Ts... tail) {
  return out_one(head, ' '), out(tail...);
}

void init_() {
  // std::ios::sync_with_stdio(false);
  // std::cin.tie(nullptr);
  std::cout << std::fixed << std::setprecision(18);
}

[[noreturn]] void exit_() {
#ifdef MY_DEBUG
  in.skip();
  assert(in.is_eof());  // Some input is left.
#endif
  fflush(stdout), fflush(stderr);
  std::cout.flush(), std::cerr.flush();
  std::_Exit(0);
}

#ifdef MY_DEBUG
#include "debug_dump.hpp"
#include "backward.hpp"
backward::SignalHandling kSignalHandling;
#else
#define DUMP(...)
#define test_case(...)
#define cerr if(false)cerr
#endif

using namespace std;

auto solve() {
  int H = in, W = in, N = in, h = in, w = in;
  auto A = vector(H, vector(W, 0));
  REP(i, H) REP(j, W) A[i][j] = in;
  vector<int> top(N + 1, H), bottom(N + 1, -1), left(N + 1, W), right(N + 1, -1);
  set<int> vals;
  REP(i, H) {
    REP(j, W) {
      int x = A[i][j];
      vals.insert(x);
      chmin(top[x], i);
      chmax(bottom[x], i);
      chmin(left[x], j);
      chmax(right[x], j);
    }
  }
  for (int k = 0; k <= H - h; ++k) {
    for (int l = 0; l <= W - w; ++l) {
      int cnt = 0;
      for (int i = 1; i <= N; ++i) {
        if (not vals.count(i)) continue;
        if (k <= top[i] and bottom[i] < k + h and l <= left[i] and right[i] < l + w) {
          ++cnt;
        }
      }
      cout << ssize(vals) - cnt << ' ';
    }
    cout << '\n';
  }

}

int main() {
  init_();
  const int T = 1;//in;
  REP(t, T) {
    test_case(t, T);
    (solve());
  }
  exit_();
}

Submission Info

Submission Time
Task E - Grid Filling
User keijak
Language C++ (GCC 9.2.1)
Score 500
Code Size 4734 Byte
Status AC
Exec Time 411 ms
Memory 4132 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 24
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_small_03.txt, 01_small_04.txt, 01_small_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 02_random_11.txt, 03_max_12.txt, 03_max_13.txt, 03_max_14.txt, 03_max_15.txt, 04_edge_16.txt, 04_edge_17.txt, 04_edge_18.txt, 04_edge_19.txt, 04_edge_20.txt, 04_edge_21.txt, 04_edge_22.txt, 04_edge_23.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 5 ms 3488 KiB
00_sample_01.txt AC 3 ms 3232 KiB
00_sample_02.txt AC 3 ms 3432 KiB
01_small_03.txt AC 3 ms 3392 KiB
01_small_04.txt AC 2 ms 3308 KiB
01_small_05.txt AC 3 ms 3380 KiB
02_random_06.txt AC 3 ms 3432 KiB
02_random_07.txt AC 103 ms 3664 KiB
02_random_08.txt AC 3 ms 3436 KiB
02_random_09.txt AC 3 ms 3392 KiB
02_random_10.txt AC 2 ms 3500 KiB
02_random_11.txt AC 2 ms 3332 KiB
03_max_12.txt AC 106 ms 3944 KiB
03_max_13.txt AC 359 ms 3932 KiB
03_max_14.txt AC 263 ms 3976 KiB
03_max_15.txt AC 54 ms 4080 KiB
04_edge_16.txt AC 367 ms 4092 KiB
04_edge_17.txt AC 186 ms 4012 KiB
04_edge_18.txt AC 53 ms 4088 KiB
04_edge_19.txt AC 14 ms 4132 KiB
04_edge_20.txt AC 411 ms 4016 KiB
04_edge_21.txt AC 116 ms 3952 KiB
04_edge_22.txt AC 24 ms 3904 KiB
04_edge_23.txt AC 33 ms 4096 KiB