結果

問題 No.940 ワープ ε=ε=ε=ε=ε=│;p>д<│
ユーザー niuezniuez
提出日時 2019-12-05 02:24:06
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 160 ms / 5,000 ms
コード長 2,776 bytes
コンパイル時間 2,966 ms
コンパイル使用メモリ 167,900 KB
実行使用メモリ 21,880 KB
最終ジャッジ日時 2023-08-21 16:22:39
合計ジャッジ時間 4,497 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,384 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 11 ms
4,384 KB
testcase_16 AC 36 ms
6,976 KB
testcase_17 AC 71 ms
11,452 KB
testcase_18 AC 94 ms
13,900 KB
testcase_19 AC 71 ms
11,396 KB
testcase_20 AC 121 ms
17,156 KB
testcase_21 AC 47 ms
8,636 KB
testcase_22 AC 113 ms
16,404 KB
testcase_23 AC 37 ms
7,188 KB
testcase_24 AC 117 ms
17,004 KB
testcase_25 AC 141 ms
19,772 KB
testcase_26 AC 160 ms
21,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define rev(i,s,e) for(i64 (i) = (s);(i) --> (e);)
#define all(x) x.begin(),x.end()

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;

template<i64 M>
struct modint {
  i64 a;
  constexpr modint(const i64 x = 0) noexcept: a((x % M + M) % M) {}
  constexpr i64 value() const noexcept { return a; }
  constexpr modint pow(i64 r) const noexcept {
    modint ans(1);
    modint aa = *this;
    while(r) {
      if(r & 1) {
        ans *= aa;
      }
      aa *= aa;
      r >>= 1;
    }
    return ans;
  }
  constexpr modint& operator+=(const modint r) noexcept {
    a += r.a;
    if(a >= M) a -= M;
    return *this;
  }
  constexpr modint& operator=(const i64 r) {
    a = (r % M + M) % M;
    return *this;
  }
  constexpr modint& operator-=(const modint r) noexcept {
    a -= r.a;
    if(a < 0) a += M;
    return *this;
  }
  constexpr modint& operator*=(const modint r) noexcept {
    a = a * r.a % M;
    return *this;
  }
  constexpr modint& operator/=(modint r) noexcept {
    i64 ex = M - 2;
    while(ex) {
      if(ex & 1) {
        *this *= r;
      }
      r *= r;
      ex >>= 1;
    }
    return *this;
  }

  constexpr modint operator+(const modint r) const {
    return modint(*this) += r;
  }
  constexpr modint operator-(const modint r) const {
    return modint(*this) -= r;
  }
  constexpr modint operator*(const modint r) const {
    return modint(*this) *= r;
  }
  constexpr modint operator/(const modint r) const {
    return modint(*this) /= r;
  }
};

using fp = modint<(i64)1e9 + 7>;

template<class T>
struct combination {
  vector<T> fact;
  vector<T> inv;

  combination(i64 n) : fact(n), inv(n) {
    fact[0] = T(1);
    for(i64 i = 1;i < n;i++)
      fact[i] = fact[i - 1] * T(i);
    inv[n - 1] = T(1) / fact[n - 1];
    for(i64 i = n - 1;i --> 0;)
      inv[i] = inv[i + 1] * T(i + 1);
  }

  T binom(i64 n, i64 k) const {
    if(k < 0 || n < k) return T(0);
    else return fact[n] * inv[k] * inv[n - k];
  }

   T H(i64 n, i64 k) const {
    return binom(n + k - 1, k);
  };

   T factor(i64 i) const { return fact[i]; }
};


int main() {
  i64 X, Y, Z;
  cin >> X >> Y >> Z;

  if(X == 0 && Y == 0 && Z == 0) {
    cout << 1 << endl;
    return 0;
  }

  combination<fp> com(X + Y + Z + 10);

  fp f(0);
  {
    fp bit(1);
    rep(i,0,X + Y + Z + 1) {
      f += bit;
      bit *= fp(2);
    }
  }

  fp ans(0);

  rep(j,0,X + Y + Z + 1) {
    fp coe = com.binom(j, X) * com.binom(j, Y) * com.binom(j, Z);
    if((j + X + Y + Z) & 1) coe *= -1;
    ans += coe * f;

    f = fp(-2) * f + fp(2).pow(X + Y + Z + 1) * com.binom(X + Y + Z + 1, j + 1);
  }

  cout << (ans / fp(2)).value() << endl;
}
0