結果

問題 No.940 ワープ ε=ε=ε=ε=ε=│;p>д<│
ユーザー risujirohrisujiroh
提出日時 2019-12-03 01:27:06
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 304 ms / 5,000 ms
コード長 1,970 bytes
コンパイル時間 3,930 ms
コンパイル使用メモリ 169,636 KB
実行使用メモリ 16,992 KB
最終ジャッジ日時 2023-08-18 23:22:04
合計ジャッジ時間 4,830 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 3 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 20 ms
4,380 KB
testcase_16 AC 62 ms
6,284 KB
testcase_17 AC 139 ms
9,232 KB
testcase_18 AC 182 ms
11,068 KB
testcase_19 AC 141 ms
9,296 KB
testcase_20 AC 234 ms
13,724 KB
testcase_21 AC 94 ms
7,296 KB
testcase_22 AC 224 ms
13,280 KB
testcase_23 AC 68 ms
6,216 KB
testcase_24 AC 227 ms
13,376 KB
testcase_25 AC 274 ms
15,524 KB
testcase_26 AC 304 ms
16,992 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

constexpr int mod = 1e9 + 7;
struct Mint {
  int v;
  Mint(long long a = 0) : v((a %= mod) < 0 ? a + mod : a) {}
  Mint& operator*=(Mint r) { v = (long long)v * r.v % mod; return *this; }
  Mint& operator/=(Mint r) { return *this *= r.inv(); }
  Mint& operator+=(Mint r) { if ((v += r.v) >= mod) v -= mod; return *this; }
  Mint& operator-=(Mint r) { if ((v -= r.v) < 0) v += mod; return *this; }
  friend Mint operator*(Mint l, Mint r) { return l *= r; }
  friend Mint operator/(Mint l, Mint r) { return l /= r; }
  friend Mint operator+(Mint l, Mint r) { return l += r; }
  friend Mint operator-(Mint l, Mint r) { return l -= r; }
  Mint pow(long long n) const {
    Mint res = 1;
    for (Mint t = *this; n; t *= t, n >>= 1) if (n & 1) res *= t;
    return res;
  }
  Mint inv() const { return pow(mod - 2); }
  friend string to_string(Mint a) { return to_string(a.v); }
};

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int a, b, c;
  cin >> a >> b >> c;
  int n = a + b + c + 1;
  vector<Mint> fact(n + 1, 1), finv(n + 1), pow2(n + 1, 1);
  for (int i = 1; i <= n; ++i) {
    fact[i] = i * fact[i - 1];
    pow2[i] = 2 * pow2[i - 1];
  }
  finv[n] = fact[n].inv();
  for (int i = n; i >= 1; --i) {
    finv[i - 1] = i * finv[i];
  }
  --n;
  auto comb = [&](int n, int k) -> Mint {
    if (k < 0 or k > n) {
      return 0;
    }
    return fact[n] * finv[k] * finv[n - k];
  };
  Mint inv2 = Mint(2).inv();
  Mint res;
  for (int S = 0; S < 1 << 3; ++S) {
    int x = a - (S >> 0 & 1);
    int y = b - (S >> 1 & 1);
    int z = c - (S >> 2 & 1);
    Mint crr, sum;
    for (int i = n; i >= 0; --i) {
      sum = comb(n + 1, i + 1) * pow2[n] - sum * inv2;
      int sgn = 3 * i - (x + y + z) & 1 ? -1 : 1;
      crr += sgn * comb(i, x) * comb(i, y) * comb(i, z) * sum;
    }
    if (__builtin_popcount(S) & 1) {
      res -= crr;
    } else {
      res += crr;
    }
  }
  cout << res.v << '\n';
}
0