結果

問題 No.895 MESE
ユーザー RTnFRTnF
提出日時 2019-09-27 22:56:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 138 ms / 2,000 ms
コード長 5,338 bytes
コンパイル時間 2,701 ms
コンパイル使用メモリ 203,924 KB
実行使用メモリ 8,324 KB
最終ジャッジ日時 2023-10-25 05:29:16
合計ジャッジ時間 7,189 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 102 ms
8,324 KB
testcase_01 AC 4 ms
8,324 KB
testcase_02 AC 102 ms
8,324 KB
testcase_03 AC 102 ms
8,324 KB
testcase_04 AC 102 ms
8,324 KB
testcase_05 AC 102 ms
8,324 KB
testcase_06 AC 103 ms
8,324 KB
testcase_07 AC 102 ms
8,324 KB
testcase_08 AC 102 ms
8,324 KB
testcase_09 AC 102 ms
8,324 KB
testcase_10 AC 103 ms
8,324 KB
testcase_11 AC 102 ms
8,324 KB
testcase_12 AC 102 ms
8,324 KB
testcase_13 AC 113 ms
8,324 KB
testcase_14 AC 131 ms
8,324 KB
testcase_15 AC 133 ms
8,324 KB
testcase_16 AC 121 ms
8,324 KB
testcase_17 AC 105 ms
8,324 KB
testcase_18 AC 138 ms
8,324 KB
testcase_19 AC 137 ms
8,324 KB
testcase_20 AC 137 ms
8,324 KB
testcase_21 AC 138 ms
8,324 KB
testcase_22 AC 138 ms
8,324 KB
testcase_23 AC 138 ms
8,324 KB
testcase_24 AC 138 ms
8,324 KB
testcase_25 AC 137 ms
8,324 KB
testcase_26 AC 138 ms
8,324 KB
testcase_27 AC 138 ms
8,324 KB
testcase_28 AC 138 ms
8,324 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T> >;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repb(i, n) for(ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define reprb(i, a, b) for(ll i = (a)-1; i >= (b); i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(unsigned long long x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
template<class S, class T>inline bool chmax(S &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class S, class T>inline bool chmin(S &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

// ModInt
// 参考:https://ei1333.github.io/luzhiled/snippets/math/mod-int.html
// modはコンパイル時に決定

template<ll mod> class ModInt{
public:
    ll x;
    ModInt() : x(0) {}
    ModInt(ll y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod){}
    constexpr ModInt &operator+=(const ModInt &p){
        if((x += p.x) >= mod) x -= mod;
        return *this;
    }
    constexpr ModInt &operator-=(const ModInt &p){
        if((x += mod - p.x) >= mod) x -= mod;
        return *this;
    }
    constexpr ModInt &operator*=(const ModInt &p){
        x = x * p.x % mod;
        return *this;
    }
    constexpr ModInt &operator/=(const ModInt &p){
        *this *= p.inverse();
        return *this;
    }
    constexpr ModInt operator-(){ return ModInt(-x); }
    constexpr ModInt operator+(const ModInt &p){ return ModInt(*this) += p; }
    constexpr ModInt operator-(const ModInt &p){ return ModInt(*this) -= p; }
    constexpr ModInt operator*(const ModInt &p){ return ModInt(*this) *= p; }
    constexpr ModInt operator/(const ModInt &p){ return ModInt(*this) /= p; }
    constexpr bool operator==(const ModInt &p){ return x == p.x; }
    constexpr bool operator!=(const ModInt &p){ return x != p.x; }
    constexpr ModInt inverse() const{
        ll a = x, b = mod, u = 1, v = 0, t;
        while(b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }
    constexpr ModInt pow(ll n) {
        ModInt ret(1), mul(x);
        while(n > 0) {
            if(n & 1) ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }
    friend ostream &operator<<(ostream &os, const ModInt &p){
        return os << p.x;
    }
    friend istream &operator>>(istream &is, ModInt &a){
        ll t;
        is >> t;
        a = ModInt< mod >(t);
        return (is);
    }
};

using mint = ModInt<MOD>;
using vm = vector<mint>;
using vvm = vector<vm>;

const int MAX = 300001;
mint fac[MAX], facinv[MAX];
void combInit(){
    fac[0] = mint(1);
    facinv[0] = mint(1);
    rep(i, MAX-1){
        fac[i+1] = fac[i]*(i+1);
        facinv[i+1] = fac[i+1].inverse();
    }
}
mint comb(const ll a, const ll b){
    assert(a < MAX);
    assert(b < MAX);
    if(a < 0 || b < 0 || b > a){
        return mint(0);
    }
    mint ret(1);
    ret *= fac[a];
    ret *= facinv[b];
    ret *= facinv[a-b];
    return ret;
}


int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    mint a, b, c;
    cin >> a >> b >> c;
    if(a == 1 && b == 1 && c == 1){
        cout << 1 << endl;
        return 0;
    }
    combInit();
    mint ans(0);
    /*
    // (1)
    ans += c     * (mint(2).pow(a.x+b.x+c.x-2) - 1) * comb(a.x+b.x+c.x-2, c.x)   * comb(a.x+b.x-2, b.x)   / (a.x+b.x+c.x-2);
    dump(  c,      (mint(2).pow(a.x+b.x+c.x-2) - 1) , comb(a.x+b.x+c.x-2, c.x)   , comb(a.x+b.x-2, b.x));
    cerr << ans << endl;
    // (2)
    ans -= (c-1) * (mint(2).pow(a.x+b.x+c.x-3) - 1) * comb(a.x+b.x+c.x-3, c.x-1) * comb(a.x+b.x-2, b.x)   / (a.x+b.x+c.x-3);
    dump(  (c-1) , (mint(2).pow(a.x+b.x+c.x-3) - 1) , comb(a.x+b.x+c.x-3, c.x-1) , comb(a.x+b.x-2, b.x));
    ans -= mint(2).pow(a.x+b.x+c.x-3) * comb(a.x+b.x+c.x-3, c.x-1) * comb(a.x+b.x-2, b.x);
    dump(  mint(2).pow(a.x+b.x+c.x-3) , comb(a.x+b.x+c.x-3, c.x-1) , comb(a.x+b.x-2, b.x));
    cerr << ans << endl;
    // (3)
    ans += c     * (mint(2).pow(a.x+b.x+c.x-2) - 1) * comb(a.x+b.x+c.x-2, c.x)   * comb(a.x+b.x-2, b.x-1) / (a.x+b.x+c.x-2);
    dump(  c     , (mint(2).pow(a.x+b.x+c.x-2) - 1) , comb(a.x+b.x+c.x-2, c.x)   , comb(a.x+b.x-2, b.x-1));
     */
    repr(i, 1, a.x+1){
        ans += c * comb(a.x+b.x+c.x-i-1, c.x) * comb(a.x+b.x-i-1, b.x-1) * (mint(2).pow(a.x+b.x+c.x-i-1) - 1) / (a.x+b.x+c.x-i-1);
        dump(c , comb(a.x+b.x+c.x-i-1, c.x) , comb(a.x+b.x-i-1, b.x-1) , (mint(2).pow(a.x+b.x+c.x-i-1) - 1));
    }
    
    cout << ans << endl;
    return 0;
}
0