提出 #36081544


ソースコード 拡げる

// #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 StdinReader {
 public:
  StdinReader() : p{buf} {
    const size_t len = fread /* _unlocked */ (buf, 1, sizeof(buf) - 1, stdin);
    buf[len] = '\0';
    bufend = buf + len;
  }

  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 {
    StdinReader<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}; }

  void skip() {
    while (isspace(*p)) ++p;
  }

  bool is_eof() { return p >= bufend; }

 private:
  static inline char buf[BufSize];
  char *p, *bufend;

  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 = (*p == '-') ? (++p, -1) : 1;
    }
    x = 0;
    while (isdigit(*p)) x = x * 10 + (*p++ & 0x0F);
    if constexpr (std::is_signed_v<T>) {
      x *= sign;
    }
  }
  void read_one(std::string &s) {
    char *p0 = p;
    while (not isspace(*p)) p++;
    s.assign(p0, p);
  }
  void read_one(std::string_view &s) {
    const char *p0 = p;
    while (not isspace(*p)) p++;
    s = std::string_view(p0, p - p0);
  }
};
StdinReader<(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_(bool interactive = false) {
  std::ios::sync_with_stdio(false);
  if (not interactive) 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 n = in, m = in;
  vector<int> a = in(n);
  auto dp = vector(n + 1, vector(m + 1, vector(2, kBig<int>)));
  dp[0][0][0] = 0;
  REP(i, n) {
    REP(j, m + 1) {
      if (dp[i][j][0] != kBig<int>) {
        if (j + a[i] <= m) chmin(dp[i + 1][j + a[i]][0], dp[i][j][0]);
        chmin(dp[i + 1][j][1], dp[i][j][0] + 1);
      }
      if (dp[i][j][1] != kBig<int>) {
        if (j + a[i] <= m) chmin(dp[i + 1][j + a[i]][0], dp[i][j][1]);
        chmin(dp[i + 1][j][1], dp[i][j][1]);
      }
    }
  }
  REP(i, 1, m + 1) {
    int ans = min(dp[n][i][0], dp[n][i][1]);
    out(ans == kBig<int> ? -1 : ans);
  }
}

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

提出情報

提出日時
問題 F - Erase Subarrays
ユーザ keijak
言語 C++ (GCC 9.2.1)
得点 500
コード長 4477 Byte
結果 AC
実行時間 630 ms
メモリ 496060 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 500 / 500
結果
AC × 3
AC × 38
セット名 テストケース
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_oneone_00.txt, 01_oneone_01.txt, 02_srnd_00.txt, 02_srnd_01.txt, 02_srnd_02.txt, 02_srnd_03.txt, 02_srnd_04.txt, 02_srnd_05.txt, 02_srnd_06.txt, 02_srnd_07.txt, 03_rnd_00.txt, 03_rnd_01.txt, 03_rnd_02.txt, 03_rnd_03.txt, 03_rnd_04.txt, 03_rnd_05.txt, 03_rnd_06.txt, 03_rnd_07.txt, 04_gcd_00.txt, 04_gcd_01.txt, 04_gcd_02.txt, 04_gcd_03.txt, 05_max_00.txt, 05_max_01.txt, 05_max_02.txt, 06_two_00.txt, 06_two_01.txt, 06_two_02.txt, 06_two_03.txt, 06_two_04.txt, 06_two_05.txt, 07_pow_00.txt, 07_pow_01.txt, 07_pow_02.txt, 07_pow_03.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 7 ms 3296 KiB
00_sample_01.txt AC 2 ms 3336 KiB
00_sample_02.txt AC 2 ms 3472 KiB
01_oneone_00.txt AC 2 ms 3456 KiB
01_oneone_01.txt AC 2 ms 3368 KiB
02_srnd_00.txt AC 4 ms 3720 KiB
02_srnd_01.txt AC 5 ms 4172 KiB
02_srnd_02.txt AC 9 ms 4524 KiB
02_srnd_03.txt AC 8 ms 5832 KiB
02_srnd_04.txt AC 18 ms 8564 KiB
02_srnd_05.txt AC 20 ms 13900 KiB
02_srnd_06.txt AC 36 ms 24500 KiB
02_srnd_07.txt AC 64 ms 45320 KiB
03_rnd_00.txt AC 620 ms 492576 KiB
03_rnd_01.txt AC 629 ms 493276 KiB
03_rnd_02.txt AC 626 ms 495120 KiB
03_rnd_03.txt AC 624 ms 493180 KiB
03_rnd_04.txt AC 623 ms 493612 KiB
03_rnd_05.txt AC 621 ms 491948 KiB
03_rnd_06.txt AC 623 ms 492628 KiB
03_rnd_07.txt AC 627 ms 494056 KiB
04_gcd_00.txt AC 630 ms 495904 KiB
04_gcd_01.txt AC 627 ms 495692 KiB
04_gcd_02.txt AC 622 ms 495704 KiB
04_gcd_03.txt AC 622 ms 495356 KiB
05_max_00.txt AC 612 ms 496004 KiB
05_max_01.txt AC 613 ms 495816 KiB
05_max_02.txt AC 618 ms 496008 KiB
06_two_00.txt AC 611 ms 495960 KiB
06_two_01.txt AC 621 ms 496052 KiB
06_two_02.txt AC 623 ms 496060 KiB
06_two_03.txt AC 616 ms 495992 KiB
06_two_04.txt AC 619 ms 495824 KiB
06_two_05.txt AC 620 ms 496004 KiB
07_pow_00.txt AC 621 ms 495704 KiB
07_pow_01.txt AC 621 ms 495616 KiB
07_pow_02.txt AC 623 ms 495700 KiB
07_pow_03.txt AC 621 ms 495796 KiB