結果

問題 No.1214 Market
ユーザー noshi91noshi91
提出日時 2020-08-30 18:00:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 6,511 bytes
コンパイル時間 1,096 ms
コンパイル使用メモリ 102,472 KB
実行使用メモリ 1,127,604 KB
最終ジャッジ日時 2024-11-15 14:52:51
合計ジャッジ時間 37,029 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,496 KB
testcase_01 AC 2 ms
16,256 KB
testcase_02 TLE -
testcase_03 MLE -
testcase_04 MLE -
testcase_05 RE -
testcase_06 TLE -
testcase_07 MLE -
testcase_08 RE -
testcase_09 RE -
testcase_10 MLE -
testcase_11 RE -
testcase_12 TLE -
testcase_13 MLE -
testcase_14 RE -
testcase_15 MLE -
testcase_16 MLE -
testcase_17 MLE -
testcase_18 RE -
testcase_19 MLE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 MLE -
testcase_24 MLE -
testcase_25 RE -
testcase_26 MLE -
testcase_27 TLE -
testcase_28 MLE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 MLE -
testcase_33 MLE -
testcase_34 RE -
testcase_35 MLE -
testcase_36 MLE -
testcase_37 RE -
testcase_38 MLE -
testcase_39 AC 4 ms
6,688 KB
testcase_40 AC 2 ms
6,692 KB
testcase_41 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

//#define NDEBUG

#pragma region cp_template

#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <utility>
#include <vector>

namespace n91 {

  using i32 = std::int32_t;
  using i64 = std::int64_t;
  using u32 = std::uint32_t;
  using u64 = std::uint64_t;
  using isize = std::ptrdiff_t;
  using usize = std::size_t;

  struct rep {
    struct itr {
      usize i;
      constexpr itr(const usize i) noexcept : i(i) {}
      void operator++() noexcept { ++i; }
      constexpr usize operator*() const noexcept { return i; }
      constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
    };
    const itr f, l;
    constexpr rep(const usize f, const usize l) noexcept
      : f(std::min(f, l)), l(l) {}
    constexpr auto begin() const noexcept { return f; }
    constexpr auto end() const noexcept { return l; }
  };
  struct revrep {
    struct itr {
      usize i;
      constexpr itr(const usize i) noexcept : i(i) {}
      void operator++() noexcept { --i; }
      constexpr usize operator*() const noexcept { return i; }
      constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
    };
    const itr f, l;
    constexpr revrep(const usize f, const usize l) noexcept
      : f(l - 1), l(std::min(f, l) - 1) {}
    constexpr auto begin() const noexcept { return f; }
    constexpr auto end() const noexcept { return l; }
  };
  template <class T> auto md_vec(const usize n, const T& value) {
    return std::vector<T>(n, value);
  }
  template <class... Args> auto md_vec(const usize n, Args... args) {
    return std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
  }
  template <class T> constexpr T difference(const T& a, const T& b) noexcept {
    return a < b ? b - a : a - b;
  }
  template <class T> void chmin(T& a, const T& b) noexcept {
    if (b < a)
      a = b;
  }
  template <class T> void chmax(T& a, const T& b) noexcept {
    if (a < b)
      a = b;
  }
  template <class F> class rec_lambda {
    F f;

  public:
    rec_lambda(F&& f) : f(std::move(f)) {}
    template <class... Args> auto operator()(Args&&... args) const {
      return f(*this, std::forward<Args>(args)...);
    }
  };
  template <class F> auto make_rec(F&& f) { return rec_lambda<F>(std::move(f)); }
  template <class T> T scan() {
    T ret;
    std::cin >> ret;
    return ret;
  }
  constexpr char eoln = '\n';
  template <class T> T ceildiv(const T& l, const T& r) {
    return l / r + (l % r != 0 ? 1 : 0);
  }

} // namespace n91

#pragma endregion cp_template

#include <cstdint>

template <std::uint_fast64_t mod> class modint {
  using u64 = std::uint_fast64_t;

public:
  u64 v;

  constexpr modint(const u64 x = 0) noexcept : v(x% mod) {}
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint& operator+=(const modint rhs) noexcept {
    v += rhs.v;
    if (v >= mod)
      v -= mod;
    return *this;
  }
  constexpr modint& operator-=(const modint rhs) noexcept {
    if (v < rhs.v)
      v += mod;
    v -= rhs.v;
    return *this;
  }
  constexpr modint& operator*=(const modint rhs) noexcept {
    v = v * rhs.v % mod;
    return *this;
  }
  constexpr modint& operator/=(modint rhs) noexcept {
    u64 exp = mod - 2;
    while (exp != 0) {
      if (exp % 2 != 0)
        *this *= rhs;
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};

#include <functional>
#include <utility>

namespace n91 {

  template <class T, class U, class Operate = std::multiplies<T>>
  constexpr T power(T base, U exp, const Operate& oper = Operate(), T iden = 1) {
    while (exp != 0) {
      if (exp % 2 != 0) {
        iden = oper(iden, base);
      }
      exp /= 2;
      base = oper(base, base);
    }
    return iden;
  }

} // namespace n91

namespace n91 {

  void main_() {
    using mint = modint<1000000007>;
    /*
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    //*/
    const usize n = scan<usize>();
    const usize m = scan<usize>();
    const usize k = scan<usize>();
    std::vector<usize> a(m);
    std::vector<u32> b(m);
    for (const usize i : rep(0, m)) {
      std::cin >> a[i] >> b[i];
    }
    std::vector<mint> fact(n + 1), ifa(n + 1);
    fact[0] = 1;
    for (const usize i : rep(1, n + 1)) {
      fact[i] = fact[i - 1] * i;
    }
    ifa[n] = mint(1) / fact[n];
    for (const usize i : revrep(1, n + 1)) {
      ifa[i - 1] = ifa[i] * i;
    }
    mint ans = 0;
    for (const usize i : rep(0, m)) {
      std::vector<usize> cnt(k + 1, 0);
      for (const usize j : rep(0, m)) {
        if (b[j] > b[i]) {
          cnt[a[j]] += 1;
        }
      }
      auto dp0 = md_vec(n + 1, m, mint(0));
      auto nx0 = dp0;
      auto dp1 = md_vec(n + 1, mint(0));
      auto nx1 = dp1;
      dp0[0][0] = mint(b[i]) * power(mint(1) / mint(k + 1), n) * fact[n];
      for (const usize j : rep(0, k + 1)) {
        {
          // 品
          for (auto& v : dp0) {
            for (const usize l : revrep(cnt[j], m)) {
              v[l] = v[l - cnt[j]];
            }
            for (const usize l : rep(0, cnt[j])) {
              v[l] = 0;
            }
          }
          // 客
          for (const usize l : rep(0, n + 1)) {
            for (const usize o : rep(0, m)) {
              for (const usize p : rep(0, n + 1)) {
                if (l + p > n) {
                  break;
                }
                if (o < p && a[i] <= j) {
                  nx1[l + p] += dp0[l][o] * ifa[p];
                }
                else {
                  nx0[l + p][o - std::min(o, p)] += dp0[l][o] * ifa[p];
                }
              }
            }
            for (const usize p : rep(0, n + 1)) {
              if (l + p > n) {
                break;
              }
              nx1[l + p] += dp1[l] * ifa[p];
            }
          }
        }

        std::swap(dp0, nx0);
        std::swap(dp1, nx1);
        for (auto& v : nx0) {
          std::fill(v.begin(), v.end(), mint(0));
        }
        std::fill(nx1.begin(), nx1.end(), mint(0));
      }
      ans += dp1[n];
    }
    std::cout << ans.v << eoln;
  }

} // namespace n91

int main() {
  n91::main_();
  return 0;
}
0