結果

問題 No.949 飲酒プログラミングコンテスト
ユーザー kyawashellkyawashell
提出日時 2020-06-22 14:39:26
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 284 ms / 2,500 ms
コード長 6,261 bytes
コンパイル時間 926 ms
コンパイル使用メモリ 96,572 KB
実行使用メモリ 73,760 KB
最終ジャッジ日時 2023-08-20 15:37:41
合計ジャッジ時間 5,808 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 4 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 194 ms
53,120 KB
testcase_12 AC 201 ms
53,804 KB
testcase_13 AC 174 ms
47,760 KB
testcase_14 AC 22 ms
9,212 KB
testcase_15 AC 115 ms
37,504 KB
testcase_16 AC 222 ms
67,292 KB
testcase_17 AC 30 ms
11,360 KB
testcase_18 AC 270 ms
70,532 KB
testcase_19 AC 127 ms
53,564 KB
testcase_20 AC 26 ms
13,416 KB
testcase_21 AC 8 ms
7,392 KB
testcase_22 AC 14 ms
12,152 KB
testcase_23 AC 3 ms
4,452 KB
testcase_24 AC 142 ms
39,964 KB
testcase_25 AC 282 ms
73,620 KB
testcase_26 AC 283 ms
73,688 KB
testcase_27 AC 248 ms
73,624 KB
testcase_28 AC 284 ms
73,756 KB
testcase_29 AC 189 ms
73,760 KB
testcase_30 AC 104 ms
73,640 KB
testcase_31 AC 75 ms
73,624 KB
testcase_32 AC 259 ms
73,628 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdint.h>
#include <stdlib.h>

#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
using default_counter_t = int64_t;

// macro
#define let auto const&
#define overload4(a, b, c, d, name, ...) name
#define rep1(n) \
  for (default_counter_t i = 0, end_i = default_counter_t(n); i < end_i; ++i)
#define rep2(i, n)                                                           \
  for (default_counter_t i = 0, end_##i = default_counter_t(n); i < end_##i; \
       ++i)
#define rep3(i, a, b)                                    \
  for (default_counter_t i       = default_counter_t(a), \
                         end_##i = default_counter_t(b); \
       i < end_##i; ++i)
#define rep4(i, a, b, c)                                 \
  for (default_counter_t i       = default_counter_t(a), \
                         end_##i = default_counter_t(b); \
       i < end_##i; i += default_counter_t(c))
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)

#define rrep1(n) \
  for (default_counter_t i = default_counter_t(n) - 1; i >= 0; --i)
#define rrep2(i, n) \
  for (default_counter_t i = default_counter_t(n) - 1; i >= 0; --i)
#define rrep3(i, a, b)                                         \
  for (default_counter_t i         = default_counter_t(b) - 1, \
                         begin_##i = default_counter_t(a);     \
       i >= begin_##i; --i)
#define rrep4(i, a, b, c)                                          \
  for (default_counter_t                                           \
           i = (default_counter_t(b) - default_counter_t(a) - 1) / \
                   default_counter_t(c) * default_counter_t(c) +   \
               default_counter_t(a),                               \
           begin_##i = default_counter_t(a);                       \
       i >= begin_##i; i -= default_counter_t(c))
#define rrep(...) \
  overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)

#define ALL(f, c, ...)                                           \
  (([&](decltype((c)) cccc) {                                    \
    return (f)(std::begin(cccc), std::end(cccc), ##__VA_ARGS__); \
  })(c))

// function
template <class C>
constexpr C& Sort(C& a) {
  std::sort(std::begin(a), std::end(a));
  return a;
}
template <class C>
constexpr auto& Min(C const& a) {
  return *std::min_element(std::begin(a), std::end(a));
}
template <class C>
constexpr auto& Max(C const& a) {
  return *std::max_element(std::begin(a), std::end(a));
}
template <class C>
constexpr auto Total(C const& c) {
  return std::accumulate(std::begin(c), std::end(c), C(0));
}
template <typename T>
auto CumSum(std::vector<T> const& v) {
  std::vector<T> a(v.size() + 1, T(0));
  for (std::size_t i = 0; i < a.size() - size_t(1); ++i) a[i + 1] = a[i] + v[i];
  return a;
}
template <typename T>
constexpr bool ChMax(T& a, T const& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
constexpr bool ChMin(T& a, T const& b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}

void In(void) { return; }

template <typename First, typename... Rest>
void In(First& first, Rest&... rest) {
  cin >> first;
  In(rest...);
  return;
}

template <class T, typename I>
void VectorIn(vector<T>& v, const I n) {
  v.resize(size_t(n));
  rep(i, v.size()) cin >> v[i];
}

void Out(void) {
  cout << "\n";
  return;
}

template <typename First, typename... Rest>
void Out(First first, Rest... rest) {
  cout << first << " ";
  Out(rest...);
  return;
}

constexpr auto yes(const bool c) { return c ? "yes" : "no"; }
constexpr auto Yes(const bool c) { return c ? "Yes" : "No"; }
constexpr auto YES(const bool c) { return c ? "YES" : "NO"; }

// http://koturn.hatenablog.com/entry/2018/08/01/010000
template <typename T, typename U>
inline std::vector<U> MakeNdVector(T n, U val) noexcept {
  static_assert(std::is_integral<T>::value,
                "[MakeNdVector] The 1st argument must be an integer");
  return std::vector<U>(std::forward<T>(n), std::forward<U>(val));
}

template <typename T, typename... Args>
inline decltype(auto) MakeNdVector(T n, Args&&... args) noexcept {
  static_assert(std::is_integral<T>::value,
                "[MakeNdVector] The 1st argument must be an integer");
  return std::vector<decltype(MakeNdVector(std::forward<Args>(args)...))>(
      std::forward<T>(n), MakeNdVector(std::forward<Args>(args)...));
}

template <typename T, std::size_t N,
          typename std::enable_if<(N > 0), std::nullptr_t>::type = nullptr>
struct NdvectorImpl {
  using type = std::vector<typename NdvectorImpl<T, N - 1>::type>;
};  // struct ndvector_impl

template <typename T>
struct NdvectorImpl<T, 1> {
  using type = std::vector<T>;
};  // struct ndvector_impl

template <typename T, std::size_t N>
using NdVector = typename NdvectorImpl<T, N>::type;

#ifdef USE_STACK_TRACE_LOGGER
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Weverything"
#include <glog/logging.h>
#pragma clang diagnostic pop
#endif  //__clang__
#endif  // USE_STACK_TRACE_LOGGER

signed main(int argc, char* argv[]) {
  (void)argc;
#ifdef USE_STACK_TRACE_LOGGER
  google::InitGoogleLogging(argv[0]);
  google::InstallFailureSignalHandler();
#else
  (void)argv;
#endif  // USE_STACK_TRACE_LOGGER
  int64_t N;
  In(N);
  vector<int64_t> A(N + 1), B(N + 1), D(N);
  rep(i, N + 1) In(A[i]);
  rep(i, N + 1) In(B[i]);
  rep(i, N) In(D[i]);

  auto dp = MakeNdVector(N + 1, N + 1, int64_t(N));

  ALL(sort, D, greater<int64_t>());

  dp[0][0] = -1;
  rep(i, N) {
    rep(j, i + 1) {
      if (dp[i][j] + 1 >= N) continue;

      auto func = [&](const int64_t l, const int64_t ab) {
        int64_t m = (dp[i][j] < 0 ? 1000000 : D[dp[i][j]]);
        ChMin(m, ab);
        int64_t k = lower_bound(D.begin() + (dp[i][j] + 1), D.end(), m,
                                greater<int64_t>()) -
                    D.begin();
        ChMin(dp[i + 1][l], k);
      };
      func(j, A[j] + B[i - j + 1]);
      if (j + 1 <= N) func(j + 1, A[j + 1] + B[i - j]);
    }
  }
  int64_t ans = 0;
  rep(i, N + 1) {
    rep(j, i + 1) {
      if (dp[i][j] < N) {
        ChMax(ans, i);
      }
    }
  }
  cout << ans << endl;
  return EXIT_SUCCESS;
}
0