結果

問題 No.940 ワープ ε=ε=ε=ε=ε=│;p>д<│
ユーザー noshi91
提出日時 2019-12-03 01:30:30
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 68 ms / 5,000 ms
コード長 974 bytes
コンパイル時間 894 ms
コンパイル使用メモリ 70,100 KB
実行使用メモリ 40,712 KB
最終ジャッジ日時 2024-11-28 11:19:38
合計ジャッジ時間 2,429 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

using ll = long long;
constexpr ll mod = 1000000007;

struct pre {
  std::vector<ll> fact, inv;
  pre(ll n) : fact(n), inv(n) {
    fact[0] = 1;
    for (ll i = 1; i < n; i += 1)
      fact[i] = fact[i - 1] * i % mod;
    inv[n - 1] = 1;
    ll exp = mod - 2, base = fact[n - 1];
    while (exp) {
      if (exp % 2)
        inv[n - 1] = inv[n - 1] * base % mod;
      base = base * base % mod;
      exp /= 2;
    }
    for (ll i = n; --i;)
      inv[i - 1] = inv[i] * i % mod;
  }
  ll c(ll n, ll r) { return fact[n] * inv[r] % mod * inv[n - r] % mod; }
  ll h(ll n, ll r) { return c(n + r - 1, n); }
};

int main() {
  ll x, y, z;
  std::cin >> x >> y >> z;
  ll s = x + y + z + 1;
  pre p(s * 2);
  ll ans = s == 1 ? 1 : 0, coef = 1;
  for (ll k = s; --k;) {
    ans = (ans + coef * p.h(x, k) % mod * p.h(y, k) % mod * p.h(z, k)) % mod;
    coef = (coef * 2 + p.c(s, k) * (s + k & 1 ? mod - 1 : 1)) % mod;
  }
  std::cout << ans;
}
0