結果

問題 No.940 ワープ ε=ε=ε=ε=ε=│;p>д<│
ユーザー risujirohrisujiroh
提出日時 2019-12-03 01:27:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 304 ms / 5,000 ms
コード長 1,970 bytes
コンパイル時間 1,823 ms
コンパイル使用メモリ 171,392 KB
実行使用メモリ 17,280 KB
最終ジャッジ日時 2024-05-06 06:04:53
合計ジャッジ時間 4,646 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 4 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 20 ms
5,376 KB
testcase_16 AC 63 ms
6,272 KB
testcase_17 AC 142 ms
9,600 KB
testcase_18 AC 183 ms
11,392 KB
testcase_19 AC 141 ms
9,472 KB
testcase_20 AC 238 ms
13,804 KB
testcase_21 AC 93 ms
7,296 KB
testcase_22 AC 224 ms
13,320 KB
testcase_23 AC 69 ms
6,400 KB
testcase_24 AC 228 ms
13,560 KB
testcase_25 AC 273 ms
15,744 KB
testcase_26 AC 304 ms
17,280 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