結果

問題 No.1044 正直者大学
ユーザー KoDKoD
提出日時 2020-05-01 22:10:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 4,537 bytes
コンパイル時間 1,010 ms
コンパイル使用メモリ 78,060 KB
最終ジャッジ日時 2024-11-14 22:28:48
合計ジャッジ時間 1,561 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp:124:8: error: 'array' in namespace 'std' does not name a template type
  124 |   std::array<value_type, size + 1> fact{};
      |        ^~~~~
main.cpp:7:1: note: 'std::array' is defined in header '<array>'; did you forget to '#include <array>'?
    6 | #include <numeric>
  +++ |+#include <array>
    7 | 
main.cpp:125:8: error: 'array' in namespace 'std' does not name a template type
  125 |   std::array<value_type, size + 1> fact_inv{};
      |        ^~~~~
main.cpp:125:3: note: 'std::array' is defined in header '<array>'; did you forget to '#include <array>'?
  125 |   std::array<value_type, size + 1> fact_inv{};
      |   ^~~
main.cpp: In constructor 'constexpr factorials<T, N>::factorials()':
main.cpp:128:5: error: 'fact' was not declared in this scope
  128 |     fact.front() = value_type(1);
      |     ^~~~
main.cpp:132:5: error: 'fact_inv' was not declared in this scope
  132 |     fact_inv.back() = ~fact.back();
      |     ^~~~~~~~
main.cpp: In member function 'constexpr factorials<T, N>::value_type factorials<T, N>::operator()(std::size_t, std::size_t) const':
main.cpp:139:12: error: 'fact' was not declared in this scope
  139 |     return fact[n] * fact_inv[n - r] * fact_inv[r];
      |            ^~~~
main.cpp:139:22: error: 'fact_inv' was not declared in this scope
  139 |     return fact[n] * fact_inv[n - r] * fact_inv[r];
      |                      ^~~~~~~~
main.cpp: In function 'int main()':
main.cpp:161:27: error: 'class factorials<modulo_int<std::integral_constant<int, 1000000007> >, 200000>' has no member named 'fact'
  161 |   std::cout << ans * fact.fact[N - 1] * fact.fact[M] << '\n';
      |                           ^~~~
main.cpp:161:46: error: 'class factorials<modulo_int<std::integral_constant<int, 1000000007> >, 200000>' has no member named 'fact'
  161 |   std::cout << ans * fact.fact[N - 1] * fact.fact[M] << '\n';
      |                                              ^~~~

ソースコード

diff #

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

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

// [l, r) from l to r
struct range {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { ++i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr range(int l_, int r_): l(l_), r(std::max(l_, r_)) { }
  constexpr itr begin() const { return l; }
  constexpr itr end() const { return r; }
};

// [l, r) from r to l
struct revrange {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { --i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr revrange(int l_, int r_): l(l_ - 1), r(std::max(l_, r_) - 1) { }
  constexpr itr begin() const { return r; }
  constexpr itr end() const { return l; }
};

template <class T>
class modulo_int {
public:
  static constexpr int mod = T::value;
  static_assert(mod > 0, "mod must be positive");
private:
  long long value;
  constexpr void normalize() {
    value %= mod;
    if (value < 0) value += mod;
  }
public:
  constexpr modulo_int(long long value_ = 0): value(value_) { normalize(); }
  constexpr modulo_int operator - () const { return modulo_int(mod - value); }
  constexpr modulo_int operator ~ () const { return power(mod - 2); }
  constexpr long long operator () () const { return value; }
  constexpr modulo_int operator + (const modulo_int &rhs) const { return modulo_int(*this) += rhs; }
  constexpr modulo_int &operator += (const modulo_int &rhs) {
    if ((value += rhs.value) >= mod) value -= mod;
    return (*this);
  }
  constexpr modulo_int operator - (const modulo_int &rhs) const { return modulo_int(*this) -= rhs; }
  constexpr modulo_int &operator -= (const modulo_int &rhs) {
    if ((value += mod - rhs.value) >= mod) value -= mod;
    return (*this);
  }
  constexpr modulo_int operator * (const modulo_int &rhs) const { return modulo_int(*this) *= rhs; }
  constexpr modulo_int &operator *= (const modulo_int &rhs) {
    (value *= rhs.value) %= mod;
    return (*this);
  }
  constexpr modulo_int operator / (const modulo_int &rhs) const { return modulo_int(*this) /= rhs; }
  constexpr modulo_int &operator /= (const modulo_int &rhs) {
    return (*this) *= ~rhs;
  }
  constexpr bool operator == (const modulo_int &rhs) const {
    return value == rhs();
  }
  constexpr bool operator != (const modulo_int &rhs) const {
    return value != rhs();
  }
  constexpr modulo_int power (uint64_t exp) const {
    modulo_int result(1), mult(*this);
    while (exp > 0) {
      if (exp & 1) result *= mult;
      mult *= mult;
      exp >>= 1;
    }
    return result;
  }
  friend std::istream &operator >> (std::istream &stream, modulo_int &lhs) {
    stream >> lhs.value;
    lhs.normalize();
    return stream;
  }
  friend std::ostream &operator << (std::ostream &stream, const modulo_int &rhs) {
    return stream << rhs.value;
  }
};


template <class T, std::size_t N>
class factorials {
public:
  using value_type = T;
  static constexpr std::size_t size = N;

public:
  std::array<value_type, size + 1> fact{};
  std::array<value_type, size + 1> fact_inv{};

  constexpr factorials() {
    fact.front() = value_type(1);
    for (std::size_t i = 1; i <= size; ++i) {
      fact[i] = fact[i - 1] * value_type(i);
    }
    fact_inv.back() = ~fact.back();
    for (std::size_t i = size; i > 0; --i) {
      fact_inv[i - 1] = fact_inv[i] * value_type(i);
    }
  }

  constexpr value_type operator () (std::size_t n, std::size_t r) const {
    return fact[n] * fact_inv[n - r] * fact_inv[r];
  }

};

using modint = modulo_int<std::integral_constant<int, 1000000007>>;
factorials<modint, 200000> fact;

int main() {
  int N, M, K;
  std::cin >> N >> M >> K;
  modint ans;
  for (int i: range(1, N + 1)) {
    if (N + M - 2 * i >= K) {
      int room = i;
      int people = M - room;
      if (people < 0) {
        continue;
      }
      ans += fact(N, room) * fact(room + people - 1, room - 1);
    }
  }
  std::cout << ans * fact.fact[N - 1] * fact.fact[M] << '\n';
  return 0;
}
0