結果

問題 No.940 ワープ ε=ε=ε=ε=ε=│;p>д<│
ユーザー jelljell
提出日時 2019-12-04 23:46:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 594 ms / 5,000 ms
コード長 6,462 bytes
コンパイル時間 1,747 ms
コンパイル使用メモリ 173,776 KB
実行使用メモリ 60,764 KB
最終ジャッジ日時 2024-05-08 11:39:01
合計ジャッジ時間 5,726 ms
ジャッジサーバーID
(参考情報)
judge3 / 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 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 3 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 21 ms
5,376 KB
testcase_16 AC 75 ms
10,584 KB
testcase_17 AC 263 ms
32,092 KB
testcase_18 AC 283 ms
32,092 KB
testcase_19 AC 268 ms
32,100 KB
testcase_20 AC 307 ms
32,096 KB
testcase_21 AC 138 ms
17,760 KB
testcase_22 AC 321 ms
32,096 KB
testcase_23 AC 77 ms
10,588 KB
testcase_24 AC 327 ms
32,092 KB
testcase_25 AC 351 ms
32,100 KB
testcase_26 AC 594 ms
60,764 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:112:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  112 | main()
      | ^~~~

ソースコード

diff #

#include <bits/stdc++.h>

#ifndef MODULO_HPP
#define MODULO_HPP
#include <iostream>
namespace modulo
{
    template <int mod>
    class modint
    {
        int val;
      public:
        constexpr modint() : val{0} {}
        constexpr modint(long long x) : val((x %= mod) < 0 ? mod + x : x) {}
        constexpr long long get() const { return val; }
        constexpr modint &operator+=(const modint &other) { return (val += other.val) < mod ? 0 : val -= mod, *this; }
        constexpr modint &operator++() { return ++val, *this; }
        constexpr modint operator++(int) { modint t = *this; return ++val, t; }
        constexpr modint &operator-=(const modint &other) { return (val += mod - other.val) < mod ? 0 : val -= mod, *this; }
        constexpr modint &operator--() { return --val, *this; }
        constexpr modint operator--(int) { modint t = *this; return --val, t; }
        constexpr modint &operator*=(const modint &other) { return val = (long long)val * other.val % mod, *this; }
        constexpr modint &operator/=(const modint &other) { return *this *= inverse(other); }
        constexpr modint operator-() const { return modint(-val); }
        constexpr modint operator+(const modint &other) const { return modint(*this) += other; }
        constexpr modint operator-(const modint &other) const { return modint(*this) -= other; }
        constexpr modint operator*(const modint &other) const { return modint(*this) *= other; }
        constexpr modint operator/(const modint &other) const { return modint(*this) /= other; }
        constexpr bool operator==(const modint &other) const { return val == other.val; }
        constexpr bool operator!=(const modint &other) const { return val != other.val; }
        constexpr bool operator!() const { return !val; }
        friend constexpr modint inverse(const modint &other)
        {
            assert(other != 0);
            int a{mod}, b{other.val}, u{}, v{1}, t{};
            while(b) t = a / b, a ^= b ^= (a -= t * b) ^= b, u ^= v ^= (u -= t * v) ^= v;
            return modint{u};
        }
        friend constexpr modint pow(modint other, long long e)
        {
            if(e < 0) e = e % (mod - 1) + mod - 1;
            modint res{1};
            while(e) { if(e & 1) res *= other; other *= other, e >>= 1; }
            return res;
        }
        friend std::ostream &operator<<(std::ostream &s, const modint &other) { return s << other.val; }
        friend std::istream &operator>>(std::istream &s, modint &other) { long long val; other = modint{(s >> val, val)}; return s; }
    }; // class modint
    template <>
    class modint<2>
    {
        bool val;
      public:
        constexpr modint(bool x = false) : val{x} {}
        constexpr modint(int x) : val(x & 1) {}
        constexpr modint(long long x) : val(x & 1) {}
        constexpr bool get() const { return val; }
        constexpr modint &operator+=(const modint &other) { return val ^= other.val, *this; }
        constexpr modint &operator++() { return val = !val, *this; }
        constexpr modint operator++(int) { modint t = *this; return val = !val, t; }
        constexpr modint &operator-=(const modint &other) { return val ^= other.val, *this; }
        constexpr modint &operator--() { return val = !val, *this; }
        constexpr modint operator--(int) { modint t = *this; return val = !val, t; }
        constexpr modint &operator*=(const modint &other) { return val &= other.val, *this; }
        constexpr modint &operator/=(const modint &other) { return *this; }
        constexpr modint operator-() const { return *this; }
        constexpr modint operator+(const modint &other) const { return val != other.val; }
        constexpr modint operator-(const modint &other) const { return val != other.val; }
        constexpr modint operator*(const modint &other) const { return val && other.val; }
        constexpr modint operator/(const modint &other) const { return *this; }
        constexpr bool operator==(const modint &other) const { return val == other.val; }
        constexpr bool operator!=(const modint &other) const { return val != other.val; }
        constexpr bool operator!() const { return !val; }
        operator bool() const { return val; }
        friend constexpr modint inverse(const modint &other) { return other; }
        friend constexpr modint pow(const modint &other, long long exp) { return other; }
        friend std::ostream &operator<<(std::ostream &os, const modint &other) { return os << other.val; }
        friend std::istream &operator>>(std::istream &is, modint &other) { long long val; other.val = (is >> val, val & 1); return is; }
    }; // class modint specialization
} // namespace modulo
#endif

class binom_runtime
{
    const int mod;
    int n;
    std::vector<int> _fact, _inv, _invfact;
  public:
    binom_runtime(int _mod) : mod(_mod), n{2}, _fact{1, 1}, _inv{0, 1}, _invfact{1, 1} {}
    void build(int m)
    {
        for(; n <= m; n <<= 1)
        {
            _fact.resize(n << 1), _inv.resize(n << 1), _invfact.resize(n << 1);
            for(int i = n; i < n << 1; ++i)
            {
                _fact[i] = (long long)_fact[i - 1] * i % mod;
                _inv[i] = mod - (long long)mod / i * _inv[mod % i] % mod;
                _invfact[i] = (long long)_invfact[i - 1] * _inv[i] % mod;
            }
        }
    }
    long long fact(int x) { return build(x), x < 0 ? 0 : _fact[x]; }
    long long inv(int x) { return build(x), x < 0 ? 0 : _inv[x]; }
    long long invfact(int x) { return build(x), x < 0 ? 0 : _invfact[x]; }
    long long binom(int x, int y) { return fact(x) * invfact(y) % mod * invfact(x - y) % mod; }
};

using modint = modulo::modint<1000000007>;
using namespace std;

main()
{
    binom_runtime gen(1000000007);
    int X,Y,Z;

    while(cin>>X>>Y>>Z)
    {
        modint ans,s{1};
        for(int k=X+Y+Z,f=1; k>=0; --k,f^=1)
        {
            modint tmp=s;
            if(X)
            {
                tmp*=gen.binom(X+k-1,k-1);
            }
            if(Y)
            {
                tmp*=gen.binom(Y+k-1,k-1);
            }
            if(Z)
            {
                tmp*=gen.binom(Z+k-1,k-1);
            }
            ans+=tmp;
            s*=2;
            if(f)
            {
                s-=gen.binom(X+Y+Z+1,k);
            }
            else
            {
                s+=gen.binom(X+Y+Z+1,k);
            }
        }
        cout << ans << "\n";
    }
}
0