結果
| 問題 |
No.1214 Market
|
| コンテスト | |
| ユーザー |
noshi91
|
| 提出日時 | 2020-08-30 18:00:24 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 6,511 bytes |
| コンパイル時間 | 1,581 ms |
| コンパイル使用メモリ | 102,044 KB |
| 最終ジャッジ日時 | 2025-01-14 01:57:10 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 TLE * 1 |
| other | AC * 2 RE * 14 TLE * 5 MLE * 18 |
ソースコード
//#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;
}
noshi91