結果

問題 No.1044 正直者大学
ユーザー tsutajtsutaj
提出日時 2020-05-01 22:23:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 18 ms / 2,000 ms
コード長 6,788 bytes
コンパイル時間 923 ms
コンパイル使用メモリ 104,424 KB
実行使用メモリ 11,096 KB
最終ジャッジ日時 2023-08-26 14:55:51
合計ジャッジ時間 2,606 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
10,780 KB
testcase_01 AC 10 ms
10,936 KB
testcase_02 AC 10 ms
10,776 KB
testcase_03 AC 10 ms
10,948 KB
testcase_04 AC 10 ms
10,952 KB
testcase_05 AC 10 ms
11,096 KB
testcase_06 AC 18 ms
10,872 KB
testcase_07 AC 10 ms
10,940 KB
testcase_08 AC 10 ms
10,960 KB
testcase_09 AC 10 ms
10,848 KB
testcase_10 AC 11 ms
11,016 KB
testcase_11 AC 10 ms
10,840 KB
testcase_12 AC 10 ms
10,960 KB
testcase_13 AC 14 ms
10,916 KB
testcase_14 AC 10 ms
10,832 KB
testcase_15 AC 10 ms
10,948 KB
testcase_16 AC 15 ms
10,780 KB
testcase_17 AC 11 ms
10,848 KB
testcase_18 AC 13 ms
10,928 KB
testcase_19 AC 11 ms
10,860 KB
testcase_20 AC 10 ms
10,884 KB
testcase_21 AC 10 ms
10,844 KB
testcase_22 AC 10 ms
10,892 KB
testcase_23 AC 10 ms
10,844 KB
testcase_24 AC 10 ms
10,856 KB
testcase_25 AC 10 ms
10,844 KB
testcase_26 AC 10 ms
10,936 KB
testcase_27 AC 10 ms
10,828 KB
testcase_28 AC 10 ms
10,868 KB
testcase_29 AC 10 ms
10,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

// ModInt begin

using ll = long long;
template<ll mod>
struct ModInt {
    ll v;
    ll mod_pow(ll x, ll n) const {
        return (!n) ? 1 : (mod_pow((x*x)%mod,n/2) * ((n&1)?x:1)) % mod;
    }
    ModInt(ll a = 0) : v((a %= mod) < 0 ? a + mod : a) {}
    ModInt operator+ ( const ModInt& b ) const {
        return (v + b.v >= mod ? ModInt(v + b.v - mod) : ModInt(v + b.v));
    }
    ModInt operator- () const {
        return ModInt(-v);
    }
    ModInt operator- ( const ModInt& b ) const {
        return (v - b.v < 0 ? ModInt(v - b.v + mod) : ModInt(v - b.v));
    }
    ModInt operator* ( const ModInt& b ) const {return (v * b.v) % mod;}
    ModInt operator/ ( const ModInt& b ) const {return (v * mod_pow(b.v, mod-2)) % mod;}
    
    bool operator== ( const ModInt &b ) const {return v == b.v;}
    bool operator!= ( const ModInt &b ) const {return !(*this == b); }
    ModInt& operator+= ( const ModInt &b ) {
        v += b.v;
        if(v >= mod) v -= mod;
        return *this;
    }
    ModInt& operator-= ( const ModInt &b ) {
        v -= b.v;
        if(v < 0) v += mod;
        return *this;
    }
    ModInt& operator*= ( const ModInt &b ) {
        (v *= b.v) %= mod;
        return *this;
    }
    ModInt& operator/= ( const ModInt &b ) {
        (v *= mod_pow(b.v, mod-2)) %= mod;
        return *this;
    }
    ModInt pow(ll x) { return ModInt(mod_pow(v, x)); }
    // operator int() const { return int(v); }
    // operator long long int() const { return v; }
};

template<ll mod>
ModInt<mod> pow(ModInt<mod> n, ll k) {
    return ModInt<mod>(n.mod_pow(n.v, k));
}

template<ll mod>
ostream& operator<< (ostream& out, ModInt<mod> a) {return out << a.v;}
template<ll mod>
istream& operator>> (istream& in, ModInt<mod>& a) {
    in >> a.v;
    return in;
}

// ModInt end


// 各種組み合わせを求めるライブラリ
template <typename NumType>
struct Combination {
    int LIMIT;
    vector<NumType> fact_, finv_;

    Combination() {}
    Combination(int LIMIT_) : LIMIT(LIMIT_), fact_(LIMIT+1), finv_(LIMIT+1) {
        fact_[0] = finv_[LIMIT] = NumType(1);
        for(int i=1; i<=LIMIT; i++) {
            fact_[i] = fact_[i-1] * NumType(i);
        }
        
        finv_[LIMIT] /= fact_[LIMIT];
        for(int i=LIMIT-1; i>=0; i--) {
            finv_[i] = finv_[i+1] * NumType(i+1);
        }
    }

    inline NumType fact(int k) const { return fact_[k]; }
    inline NumType finv(int k) const { return finv_[k]; }
    NumType P(int n, int r) const {
        if(r < 0 or n < r) return NumType(0);
        return fact_[n] * finv_[n-r];
    }
    NumType C(int n, int r) const {
        if(r < 0 or n < r) return NumType(0);
        return fact_[n] * finv_[n-r] * finv_[r];
    }
    // 重複組み合わせ
    NumType H(int n, int r) const {
        if(n < 0 or r < 0) return NumType(0);
        return r == 0 ? NumType(1) : C(n + r - 1, r);
    }
    // ベル数 (区別できる n 個のボールを区別できない k 個以下の箱に分割)
    // B(n, n) := n 個のボールを任意個のグループに分割する場合の数
    NumType B(int n, int k) const {
        if(n == 0) return NumType(1);
        k = min(n, k);
        NumType ret(0);
        vector<NumType> pref(k + 1); pref[0] = NumType(1);
        for(int i=1; i<=k; i++) {
            if(i & 1) pref[i] = pref[i-1] - finv_[i];
            else pref[i] = pref[i-1] + finv_[i];
        }
        for(int i=1; i<=k; i++) {
            // 累乗が必要なので適宜書き換える?
            // ModInt 使うならこれでいい
            ret += NumType(i).pow(n) * finv_[i] * pref[k-i];
        }
        return ret;
    }
    // スターリング数 (区別できる n 個のボールを区別できない k 個の箱に分割)
    NumType S(int n, int k) const {
        if(n < k) return NumType(0);
        NumType ans(0);
        for(int i=0; i<=k; i++) {
            NumType val = C(k, i) * NumType(i).pow(n);
            if((k - i) % 2) ans -= val;
            else ans += val;
        }
        return ans * finv_[k];
    }

    // ランダムウォーク: 左に X 回、右に Y 回進むとき、
    // 移動途中・終了時に座標 K を超えないものを数える
    // K が非負なら左側、負なら右側領域 (?) のランダムウォーク
    NumType walk(int X, int Y, int K) {
        if(K < 0) return walk(Y, X, -K);
        if(Y <= K) return C(X+Y, X); // 引っかからない
        if(Y - X > K) return NumType(0); // そもそも合計が超える
        
        int A = Y - K - 1, B = X + K + 1;
        return C(X+Y, X) - C(A+B, A);
    }
};

// P(n, k) := n の k 分割 (k 個の 0 以上の整数の和)
template <typename NumType, int LIMIT = 3010>
struct Partition {
    vector< vector<NumType> > dp;
    Partition() : dp(LIMIT, vector<NumType>(LIMIT)) {
        for(int k=0; k<LIMIT; k++) dp[0][k] = NumType(1);
        for(int i=1; i<LIMIT; i++) {
            for(int j=1; j<LIMIT; j++) {
                dp[i][j] += dp[i][j-1];
                if(i-j >= 0) dp[i][j] += dp[i-j][j];
            }
        }
    }
    inline NumType get(int n, int k) {
        if(n < 0 or k < 0) return NumType(0);
        return dp[n][k];
    }
};

using mint = ModInt<MOD>;

int main() {
    int N, M, K; scanf("%d%d%d", &N, &M, &K);
    Combination<mint> comb(500010);

    mint ans(0);
    for(int i=2; i<=N+M; i+=2) {
        int d = i / 2;
        if(d > N or d > M or i > N+M-K) continue;
        {
            mint mul(1);
            mul *= comb.H(d, N-d) * comb.fact(N-1);
            mul *= comb.H(d, M-d) * comb.fact(M);        
            ans += mul;
        }
        if(N >= d+1) {
            mint mul(1);
            mul *= comb.H(d+1, N-d-1) * comb.fact(N-1);
            mul *= comb.H(d, M-d) * comb.fact(M);
            ans += mul;
        }
    }
    cout << ans << endl;
    return 0;
}
0