結果

問題 No.940 ワープ ε=ε=ε=ε=ε=│;p>д<│
ユーザー KumaTachiRenKumaTachiRen
提出日時 2023-11-01 11:30:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,430 ms / 5,000 ms
コード長 4,244 bytes
コンパイル時間 5,341 ms
コンパイル使用メモリ 276,256 KB
実行使用メモリ 176,736 KB
最終ジャッジ日時 2023-11-01 11:30:42
合計ジャッジ時間 15,091 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 7 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 4 ms
4,348 KB
testcase_06 AC 3 ms
4,348 KB
testcase_07 AC 3 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 3 ms
4,348 KB
testcase_10 AC 3 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 4 ms
4,348 KB
testcase_13 AC 4 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 83 ms
14,388 KB
testcase_16 AC 187 ms
38,032 KB
testcase_17 AC 678 ms
82,576 KB
testcase_18 AC 739 ms
101,700 KB
testcase_19 AC 686 ms
82,296 KB
testcase_20 AC 756 ms
125,860 KB
testcase_21 AC 354 ms
52,472 KB
testcase_22 AC 763 ms
120,664 KB
testcase_23 AC 337 ms
43,968 KB
testcase_24 AC 760 ms
123,768 KB
testcase_25 AC 1,404 ms
161,504 KB
testcase_26 AC 1,430 ms
176,736 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;
using namespace atcoder;

struct Fast {
  Fast() {
    std::cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(10);
  }
} fast;

#define all(a) (a).begin(), (a).end()
#define contains(a, x) ((a).find(x) != (a).end())
#define rep(i, a, b) for (int i = (a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (a); i--)
#define writejoin(s, a) rep(_i, 0, (a).size()) cout << (a)[_i] << (_i + 1 < (int)(a).size() ? s : "\n");
#define YN(b) cout << ((b) ? "YES" : "NO") << "\n";
#define Yn(b) cout << ((b) ? "Yes" : "No") << "\n";
#define yn(b) cout << ((b) ? "yes" : "no") << "\n";

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using mint = modint1000000007;
using vm = vector<mint>;


template <class T>
T extgcd(T a, T b, T& x, T& y) {
  for (T u = y = 1, v = x = 0; a;) {
    T q = b / a;
    swap(x -= q * u, u);
    swap(y -= q * v, v);
    swap(b -= q * a, a);
  }
  return b;
}
template <class T>
T mod_inv(T a, T m) {
  T x, y;
  extgcd(a, m, x, y);
  return (m + x % m) % m;
}
long long mod_pow(long long a, long long n, long long mod) {
  long long ret = 1;
  long long p = a % mod;
  while (n) {
    if (n & 1) ret = ret * p % mod;
    p = p * p % mod;
    n >>= 1;
  }
  return ret;
}

template <class mint>
std::vector<mint> convolution_int32mod(std::vector<mint> a, std::vector<mint> b) {
  const long long m1 = 167772161;
  const long long m2 = 469762049;
  const long long m3 = 1224736769;
  const int mod = mint::mod();
  std::vector<long long> u(a.size()), v(b.size());
  for (int i = 0; i < (int)a.size(); i++) u[i] = a[i].val();
  for (int i = 0; i < (int)b.size(); i++) v[i] = b[i].val();
  auto x = atcoder::convolution<m1>(u, v);
  auto y = atcoder::convolution<m2>(u, v);
  auto z = atcoder::convolution<m3>(u, v);

  const long long m1_inv_m2 = mod_inv<long long>(m1, m2);
  const long long m12_inv_m3 = mod_inv<long long>(m1 * m2, m3);
  const long long m12_mod = m1 * m2 % mod;
  int n = (int)x.size();
  std::vector<mint> ret(n);
  for (int i = 0; i < n; i++) {
    long long v1 = (y[i] - x[i]) * m1_inv_m2 % m2;
    if (v1 < 0) v1 += m2;
    long long v2 = (z[i] - (x[i] + m1 * v1) % m3) * m12_inv_m3 % m3;
    if (v2 < 0) v2 += m3;
    long long v3 = (x[i] + m1 * v1 + m12_mod * v2) % mod;
    if (v3 < 0) v3 += mod;
    ret[i] = v3;
  }
  return ret;
}

template <int mod>
std::vector<long long> convolution_int32mod(std::vector<long long> a, std::vector<long long> b) {
  using mint = static_modint<mod>;
  std::vector<mint> u(a.size()), v(b.size());
  for (int i = 0; i < (int)a.size(); i++) u[i] = a[i];
  for (int i = 0; i < (int)b.size(); i++) v[i] = b[i];
  auto w = convolution_int32mod(u, v);
  int n = (int)w.size();
  std::vector<long long> c(n);
  for (int i = 0; i < n; i++) c[i] = w[i].val();
  return c;
}

template <typename mint>
class Factorial {
 public:
  Factorial(int max) : n(max) {
    f = std::vector<mint>(n + 1);
    finv = std::vector<mint>(n + 1);
    f[0] = 1;
    for (int i = 1; i <= n; i++) f[i] = f[i - 1] * i;
    finv[n] = f[n].inv();
    for (int i = n; i > 0; i--) finv[i - 1] = finv[i] * i;
  }
  mint fact(int k) const {
    assert(0 <= k && k <= n);
    return f[k];
  }
  mint fact_inv(int k) const {
    assert(0 <= k && k <= n);
    return finv[k];
  }
  mint binom(int k, int r) const {
    assert(0 <= k && k <= n);
    if (r < 0 || r > k) return 0;
    return f[k] * finv[r] * finv[k - r];
  }
  mint inv(int k) const {
    assert(0 < k && k <= n);
    return finv[k] * f[k - 1];
  }

 private:
  int n;
  std::vector<mint> f, finv;
};

void solve() {
  int x, y, z;
  cin >> x >> y >> z;
  int n = x + y + z + 1;
  if (n == 1) {
    cout << 1 << endl;
    return;
  }

  Factorial<mint> fact(n * 3);
  vm f(n), g(n);
  rep(i, 0, n) {
    f[i] = i % 2 == 0 ? fact.fact_inv(i) : -fact.fact_inv(i);
    if (i) g[i] = fact.fact_inv(i) * fact.binom(x + i - 1, x) * fact.binom(y + i - 1, y) * fact.binom(z + i - 1, z);
  }
  f = convolution_int32mod(f, g);
  mint ans = 0;
  rep(i, 0, n) ans += f[i] * fact.fact(i);
  cout << ans.val() << endl;
}

int main() {
  int t = 1;
  // cin >> t;
  while (t--) solve();
}
0