結果

問題 No.1104 オンライン点呼
ユーザー KoDKoD
提出日時 2020-07-03 22:00:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,193 bytes
コンパイル時間 729 ms
コンパイル使用メモリ 78,776 KB
実行使用メモリ 5,716 KB
最終ジャッジ日時 2023-10-17 02:16:30
合計ジャッジ時間 3,198 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 83 ms
5,716 KB
testcase_02 AC 77 ms
5,716 KB
testcase_03 AC 55 ms
5,716 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 33 ms
4,660 KB
testcase_08 AC 14 ms
4,348 KB
testcase_09 AC 32 ms
5,452 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 22 ms
4,396 KB
testcase_12 AC 33 ms
4,660 KB
testcase_13 AC 28 ms
4,348 KB
testcase_14 AC 4 ms
4,348 KB
testcase_15 AC 46 ms
4,924 KB
testcase_16 WA -
testcase_17 AC 33 ms
4,396 KB
testcase_18 AC 42 ms
4,924 KB
testcase_19 AC 63 ms
5,188 KB
testcase_20 AC 68 ms
5,452 KB
testcase_21 AC 68 ms
5,452 KB
testcase_22 AC 56 ms
5,188 KB
testcase_23 AC 44 ms
4,660 KB
testcase_24 AC 20 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <utility>
#include <numeric>
#include <vector>
#include <array>

template <class T, class U>
inline bool chmin(T &lhs, const U &rhs) {
  if (lhs > rhs) { lhs = rhs; return true; }
  return false;
}

template <class T, class U>
inline bool chmax(T &lhs, const U &rhs) {
  if (lhs < rhs) { lhs = rhs; return true; }
  return false;
}

struct range {
  using itr = int64_t;
  struct iterator {
    itr i;
    constexpr iterator(itr i_) noexcept : i(i_) { }
    constexpr void operator ++ () noexcept { ++i; }
    constexpr itr operator * () const noexcept { return i; }
    constexpr bool operator != (iterator x) const noexcept { return i != x.i; }
  };
  const iterator l, r;
  constexpr range(itr l_, itr r_) noexcept : l(l_), r(std::max(l_, r_)) { }
  constexpr iterator begin() const noexcept { return l; }
  constexpr iterator end() const noexcept { return r; }
};

struct revrange {
  using itr = int64_t;
  struct iterator {
    itr i;
    constexpr iterator(itr i_) noexcept : i(i_) { }
    constexpr void operator ++ () noexcept { --i; }
    constexpr itr operator * () const noexcept { return i; }
    constexpr bool operator != (iterator x) const noexcept { return i != x.i; }
  };
  const iterator l, r;
  constexpr revrange(itr l_, itr r_) noexcept : l(l_ - 1), r(std::max(l_, r_) - 1) { }
  constexpr iterator begin() const noexcept { return r; }
  constexpr iterator end() const noexcept { return l; }
};

using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;

constexpr i32 inf32 = (i32(1) << 30) - 1;
constexpr i64 inf64 = (i64(1) << 62) - 1;

int main() {
  size_t N;
  std::cin >> N;
  if (N == 1) {
    std::cout << 0 << '\n';
    return 0;
  }
  i64 K;
  std::cin >> K;
  std::vector<i64> A(N), B(N);
  for (auto &x: A) {
    std::cin >> x;
  }
  for (auto &x: B) {
    std::cin >> x;
  }
  std::vector<i64> time(N, inf64);
  time[0] = 0;
  for (auto i: range(1, N)) {
    chmin(time[i], time[i - 1] + A[i - 1] + B[i]);
    if (i - 2 >= 0) {
      chmin(time[i], time[i - 2] + A[i - 2] + B[i] + K);
    }
  }
  std::cout << *std::max_element(time.begin(), time.end()) << '\n';
  return 0;
}
0