結果

問題 No.1111 コード進行
ユーザー KoDKoD
提出日時 2020-07-10 21:44:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 164 ms / 2,000 ms
コード長 5,969 bytes
コンパイル時間 791 ms
コンパイル使用メモリ 84,424 KB
実行使用メモリ 110,336 KB
最終ジャッジ日時 2024-10-11 08:39:39
合計ジャッジ時間 3,268 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,248 KB
testcase_03 AC 2 ms
5,248 KB
testcase_04 AC 2 ms
5,248 KB
testcase_05 AC 3 ms
5,248 KB
testcase_06 AC 5 ms
5,632 KB
testcase_07 AC 4 ms
5,376 KB
testcase_08 AC 3 ms
5,248 KB
testcase_09 AC 4 ms
5,248 KB
testcase_10 AC 5 ms
6,528 KB
testcase_11 AC 3 ms
5,248 KB
testcase_12 AC 5 ms
5,632 KB
testcase_13 AC 4 ms
5,248 KB
testcase_14 AC 8 ms
6,784 KB
testcase_15 AC 2 ms
5,248 KB
testcase_16 AC 6 ms
5,888 KB
testcase_17 AC 5 ms
6,656 KB
testcase_18 AC 2 ms
5,248 KB
testcase_19 AC 2 ms
5,248 KB
testcase_20 AC 3 ms
5,248 KB
testcase_21 AC 2 ms
5,248 KB
testcase_22 AC 6 ms
7,680 KB
testcase_23 AC 3 ms
5,248 KB
testcase_24 AC 4 ms
5,248 KB
testcase_25 AC 8 ms
7,296 KB
testcase_26 AC 5 ms
5,504 KB
testcase_27 AC 3 ms
5,248 KB
testcase_28 AC 56 ms
56,320 KB
testcase_29 AC 26 ms
24,832 KB
testcase_30 AC 54 ms
38,656 KB
testcase_31 AC 7 ms
9,216 KB
testcase_32 AC 70 ms
34,816 KB
testcase_33 AC 63 ms
23,680 KB
testcase_34 AC 39 ms
41,216 KB
testcase_35 AC 54 ms
51,968 KB
testcase_36 AC 82 ms
55,680 KB
testcase_37 AC 21 ms
15,616 KB
testcase_38 AC 23 ms
12,416 KB
testcase_39 AC 98 ms
38,144 KB
testcase_40 AC 89 ms
51,584 KB
testcase_41 AC 68 ms
62,592 KB
testcase_42 AC 42 ms
27,008 KB
testcase_43 AC 49 ms
23,936 KB
testcase_44 AC 15 ms
14,080 KB
testcase_45 AC 47 ms
38,656 KB
testcase_46 AC 3 ms
5,248 KB
testcase_47 AC 164 ms
110,336 KB
testcase_48 AC 3 ms
5,248 KB
testcase_49 AC 3 ms
5,248 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:72:45: warning: narrowing conversion of 'N' from 'i32' {aka 'int'} to 'size_t' {aka 'long unsigned int'} [-Wnarrowing]
   72 | template <uint32_t Modulus>
      |                                             ^
main.cpp:72:50: warning: narrowing conversion of '(K + 1)' from 'i32' {aka 'int'} to 'size_t' {aka 'long unsigned int'} [-Wnarrowing]
   72 | template <uint32_t Modulus>
      |                                                  ^  

ソースコード

diff #

#line 1 "main.cpp"

#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; }
};

#line 2 "/Users/kodamankod/Desktop/Programming/Library/other/gen_vec.cpp"

#include <cstddef>
#line 5 "/Users/kodamankod/Desktop/Programming/Library/other/gen_vec.cpp"
#include <type_traits>

template <class T, size_t N, size_t I = 0>
decltype(auto) gen_vec(const size_t (&)[N], typename std::enable_if<(I == N), const T&>::type value = T{}) { 
  return value; 
}

template <class T, size_t N, size_t I = 0>
decltype(auto) gen_vec(const size_t (&list)[N], typename std::enable_if<(I != N), const T&>::type value = T{}) { 
  return std::vector(list[I], gen_vec<T, N, I + 1>(list, value)); 
}
#line 2 "/Users/kodamankod/Desktop/Programming/Library/algebraic/modular.cpp"

#include <cstdint>
#line 5 "/Users/kodamankod/Desktop/Programming/Library/algebraic/modular.cpp"

template <uint32_t Modulus>
class modular {
public:
  using value_type = uint32_t;
  using max_type = uint64_t;

  static constexpr value_type mod = Modulus;
  static constexpr value_type get_mod() noexcept { return mod; }
  static_assert(mod >= 2, "invalid mod :: smaller than 2");
  static_assert(mod < (value_type(1) << 31), "invalid mod :: over 2^31");

  template <class T>
  static constexpr value_type normalize(T value_) noexcept {
    if (value_ < 0) {
      value_ = -value_;
      value_ %= mod;
      if (value_ == 0) return 0;
      return mod - value_;
    }
    return value_ % mod;
  }

private:
  value_type value;

public:
  constexpr modular() noexcept : value(0) { }
  template <class T>
  explicit constexpr modular(T value_) noexcept : value(normalize(value_)) { }
  template <class T>
  explicit constexpr operator T() const noexcept { return static_cast<T>(value); }

  constexpr value_type get() const noexcept { return value; }
  constexpr modular operator - () const noexcept { return modular(mod - value); }
  constexpr modular operator ~ () const noexcept { return inverse(); }

  constexpr value_type &extract() noexcept { return value; }
  constexpr modular inverse() const noexcept { return power(mod - 2); }
  constexpr modular power(max_type exp) const noexcept {
    modular res(1), mult(*this);
    while (exp > 0) {
      if (exp & 1) res *= mult;
      mult *= mult;
      exp >>= 1;
    }
    return res;
  }

  constexpr modular operator + (const modular &rhs) const noexcept { return modular(*this) += rhs; }
  constexpr modular& operator += (const modular &rhs) noexcept { 
    if ((value += rhs.value) >= mod) value -= mod; 
    return *this; 
  }

  constexpr modular operator - (const modular &rhs) const noexcept { return modular(*this) -= rhs; }
  constexpr modular& operator -= (const modular &rhs) noexcept { 
    if ((value += mod - rhs.value) >= mod) value -= mod; 
    return *this; 
  }

  constexpr modular operator * (const modular &rhs) const noexcept { return modular(*this) *= rhs; }
  constexpr modular& operator *= (const modular &rhs) noexcept { 
    value = (max_type) value * rhs.value % mod;
    return *this;
  }

  constexpr modular operator / (const modular &rhs) const noexcept { return modular(*this) /= rhs; }
  constexpr modular& operator /= (const modular &rhs) noexcept { return (*this) *= rhs.inverse(); }

  constexpr bool zero() const noexcept { return value == 0; }
  constexpr bool operator == (const modular &rhs) const noexcept { return value == rhs.value; }
  constexpr bool operator != (const modular &rhs) const noexcept { return value != rhs.value; }
  friend std::ostream& operator << (std::ostream &stream, const modular &rhs) {
    return stream << rhs.value;
  }

};

/**
 * @title Modint
 */
#line 53 "main.cpp"

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

using m32 = modular<1000000007>;

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

int main() {
  i32 N, M, K;
  std::cin >> N >> M >> K;
  std::vector<i32> P(M), Q(M), R(M);
  for (auto i: range(0, M)) {
    std::cin >> P[i] >> Q[i] >> R[i];
    --P[i]; --Q[i];
  }
  auto dp = gen_vec<std::array<m32, 300>>({ N, K + 1 });
  for (auto i: range(0, N)) {
    for (auto j: range(0, K + 1)) {
      dp[i][j].fill(m32(0));
    }
  }
  dp[0][0].fill(m32(1));
  for (auto i: range(0, N - 1)) {
    for (auto j: range(0, K + 1)) {
      for (auto k: range(0, M)) {
        if (j + R[k] <= K) {
          dp[i + 1][j + R[k]][Q[k]] += dp[i][j][P[k]];
        }
      }
    }
  }
  m32 ans;
  for (auto k: range(0, 300)) {
    ans += dp[N - 1][K][k];
  }
  std::cout << ans << '\n';
  return 0;
}
0