답안 #396537

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
396537 2021-04-30T08:48:06 Z Cyanmond Bali Sculptures (APIO15_sculpture) C++17
0 / 100
1 ms 332 KB
#include "bits/stdc++.h"
#pragma region cscpptemp
// require at least C++17 to compile
using llint = long long int;
template <class T>
using Heap = std::priority_queue<T>;
template <class T>
using RevHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

// ex. for (const int i : range(a, b)) ... loop [a, b)
template <class T, class = std::enable_if_t<std::is_signed_v<T>>>
class range {
  struct range_iterator {
    T itr;
    constexpr range_iterator(const int pos) noexcept : itr(pos) {}
    constexpr void operator++() noexcept { ++itr; }
    constexpr bool operator!=(const range_iterator& other) const noexcept {
      return itr != other.itr;
    }
    constexpr T operator*() const noexcept { return itr; }
  };

 public:
  constexpr range(const T first_, const T last_) noexcept
      : first(first_), last(last_) {}
  constexpr range_iterator begin() const noexcept { return first; }
  constexpr range_iterator end() const noexcept { return last; }

 private:
  const range_iterator first, last;
};

// ex. for (const int i : range(a, b)) ... revloop [a, b]
template <class T, class = std::enable_if_t<std::is_signed_v<T>>>
class revrange {
  struct revrange_iterator {
    T itr;
    constexpr revrange_iterator(const int pos) noexcept : itr(pos) {}
    constexpr void operator++() noexcept { --itr; }
    constexpr bool operator!=(const revrange_iterator& other) const noexcept {
      return itr != other.itr;
    }
    constexpr T operator*() const noexcept { return itr; }
  };

 public:
  constexpr revrange(const T first_, const T last_) noexcept
      : first(first_), last(last_ - 1) {}
  constexpr revrange_iterator begin() const noexcept { return first; }
  constexpr revrange_iterator end() const noexcept { return last; }

 private:
  const revrange_iterator first, last;
};

// ex. rec_lambda([](auto&& f, int n) -> int {return n < 1 ? 1 : f(--n); })
template <class F>
class rec_lambda {
 public:
  constexpr rec_lambda(F&& f_) : f(std::forward<F>(f_)) {}
  template <class... Args>
  constexpr auto operator()(Args&&... args) const {
    return f(*this, std::forward<Args>(args)...);
  }

 private:
  F f;
};

// ex. const int N = read()
struct read {
  template <class T>
  [[nodiscard]] operator T() {
    T ret;
    std::cin >> ret;
    return ret;
  }
};

// ex. chmax(a, b) ... a = max(a, b)
template <class T>
constexpr void chmax(T& a, const T b) noexcept {
  if (a < b) a = b;
}
template <class T>
constexpr void chmin(T& a, const T b) noexcept {
  if (a > b) a = b;
}

// ex. ceildiv(a, b) ... ceil(a / b)
template <class T, class = std::enable_if_t<std::is_integral_v<T>>>
constexpr T ceildiv(const T dividend, const T divisor) {
  return (dividend + divisor - 1) / divisor;
}

// ex. mk_vec(a, b, c, v) ... 3D vector size: [a][b][c] init value: v
template <class T>
auto mk_vec(const int n, const T value) {
  return std::vector(n, value);
}
template <class... Args>
auto mk_vec(const int n, Args... args) {
  return std::vector(n, mk_vec(args...));
}
#pragma endregion

int main() {
  const int N = read(), A = read(), B = read();
  std::vector<llint> Y(N);
  for (auto& el : Y) el = read();

  llint base = 0ll;
  for (const int bit : revrange(50, 0)) {
    llint mid = base + (1ll << bit);
    // can (max < mid) ?
    int cnt = 0;
    llint nc = 0ll;
    for (const int i : range(0, N)) {
      if (nc + Y[i] >= mid) {
        if (nc == 0) {
          cnt = 1 << 30;
          break;
        }
        ++cnt;
        nc = 0ll;
      }
      if (i == N - 1)
        ++cnt;
      nc += Y[i];
    }
    if (cnt > B) base = mid;
  }
  std::cout << base << std::endl;
  return 0;
}

Compilation message

sculpture.cpp:2: warning: ignoring #pragma region cscpptemp [-Wunknown-pragmas]
    2 | #pragma region cscpptemp
      | 
sculpture.cpp:105: warning: ignoring #pragma endregion  [-Wunknown-pragmas]
  105 | #pragma endregion
      | 
sculpture.cpp: In function 'int main()':
sculpture.cpp:108:25: warning: unused variable 'A' [-Wunused-variable]
  108 |   const int N = read(), A = read(), B = read();
      |                         ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 296 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -