結果
問題 | No.1044 正直者大学 |
ユーザー |
![]() |
提出日時 | 2020-05-01 22:50:58 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 18 ms / 2,000 ms |
コード長 | 3,692 bytes |
コンパイル時間 | 3,823 ms |
コンパイル使用メモリ | 200,444 KB |
実行使用メモリ | 6,400 KB |
最終ジャッジ日時 | 2024-12-25 13:50:19 |
合計ジャッジ時間 | 4,226 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 28 |
ソースコード
#pragma GCC optimize("Ofast")#include <bits/stdc++.h>#include <ext/pb_ds/assoc_container.hpp>#include <ext/pb_ds/tree_policy.hpp>using namespace std;using namespace __gnu_pbds;using ll = long long;using ull = unsigned long long;using pii = pair<int, int>;using pll = pair<long long, long long>;#define rep(i, n) for(int i = 0; i < (n); ++i)#define all(x) (x).begin(),(x).end()constexpr char ln = '\n';constexpr long long MOD = 1000000007LL;//constexpr long long MOD = 998244353LL;template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }////////////////////////////////////////////////////////////////////////////////////////////////////////////template <std::uint_fast64_t Modulus>struct ModInt {using u64 = std::uint_fast64_t;u64 a;constexpr ModInt(const long long x = 0) noexcept : a(x >= 0 ? x % Modulus : (Modulus - (-x) % Modulus) % Modulus) {}constexpr u64 &value() noexcept { return a; }constexpr const u64 &value() const noexcept { return a; }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 long long rhs) const noexcept {return ModInt(*this) ^= rhs;}constexpr ModInt &operator+=(const ModInt rhs) noexcept {a += rhs.a;if (a >= Modulus) {a -= Modulus;}return *this;}constexpr ModInt &operator-=(const ModInt rhs) noexcept {if (a < rhs.a) {a += Modulus;}a -= rhs.a;return *this;}constexpr ModInt &operator*=(const ModInt rhs) noexcept {a = a * rhs.a % Modulus;return *this;}constexpr ModInt &operator/=(ModInt rhs) noexcept {u64 exp = Modulus - 2;while (exp) {if (exp&1) *this *= rhs;exp >>= 1;rhs *= rhs;}return *this;}constexpr ModInt &operator^=(long long exp) noexcept {ModInt rhs = a;a = 1;while (exp) {if (exp&1) *this *= rhs;exp >>= 1;rhs *= rhs;}return *this;}bool operator==(const ModInt &p) const {return a == p.a;}bool operator!=(const ModInt &p) const {return a != p.a;}};using mint = ModInt<MOD>;struct ModCombination {vector<mint> Fac;vector<mint> Facinv;ModCombination(int x) {Fac.resize(x+1);Facinv.resize(x+1);Fac[0] = 1;for (int i = 0; i < x; ++i) Fac[i+1] = Fac[i]*(i+1);Facinv[x] = Fac[0]/Fac[x];for (int i = x; i > 0; --i) Facinv[i-1] = Facinv[i]*i;}mint get(int n, int k) {if (k < 0 || k > n) return 0;return Fac[n]*Facinv[k]*Facinv[n-k];}};int main() {ios::sync_with_stdio(false); cin.tie(nullptr);int N,M,K; cin >> N >> M >> K;ModCombination MC(N+M);mint ans = 0;for (int i = K; i <= N+M; i++) {if (N-M+i >= 0 and (N-M+i)%2==0) {int num = (N-M+i)/2;if (N - num < 1 or M - (i - num) < 1 or i - num < 0) continue;int n = N - num;ans += MC.get(N-1,n-1)*MC.get(M-1,n-1)/n;}}ans *= MC.Fac[N]*MC.Fac[M];cout << ans.a << ln;}