結果

問題 No.940 ワープ ε=ε=ε=ε=ε=│;p>д<│
ユーザー jelljell
提出日時 2020-01-09 22:22:33
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 641 ms / 5,000 ms
コード長 7,514 bytes
コンパイル時間 1,878 ms
コンパイル使用メモリ 170,640 KB
実行使用メモリ 52,376 KB
最終ジャッジ日時 2023-08-15 02:05:30
合計ジャッジ時間 18,751 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 413 ms
52,196 KB
testcase_01 AC 493 ms
52,196 KB
testcase_02 AC 470 ms
52,260 KB
testcase_03 AC 479 ms
52,156 KB
testcase_04 AC 482 ms
52,240 KB
testcase_05 AC 481 ms
52,188 KB
testcase_06 AC 486 ms
52,196 KB
testcase_07 AC 427 ms
52,188 KB
testcase_08 AC 448 ms
52,224 KB
testcase_09 AC 438 ms
52,252 KB
testcase_10 AC 468 ms
52,252 KB
testcase_11 AC 456 ms
52,168 KB
testcase_12 AC 472 ms
52,192 KB
testcase_13 AC 460 ms
52,224 KB
testcase_14 AC 452 ms
52,252 KB
testcase_15 AC 491 ms
52,172 KB
testcase_16 AC 488 ms
52,256 KB
testcase_17 AC 510 ms
52,196 KB
testcase_18 AC 538 ms
52,376 KB
testcase_19 AC 529 ms
52,236 KB
testcase_20 AC 583 ms
52,312 KB
testcase_21 AC 502 ms
52,312 KB
testcase_22 AC 574 ms
52,260 KB
testcase_23 AC 481 ms
52,264 KB
testcase_24 AC 603 ms
52,244 KB
testcase_25 AC 601 ms
52,216 KB
testcase_26 AC 641 ms
52,216 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:118:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
  118 | main()
      | ^~~~

ソースコード

diff #

#include <bits/stdc++.h>

#ifndef MODULO_HPP
#define MODULO_HPP
#include <iostream>
#include <cassert>
template <int mod>
class modint
{
    int val;
  public:
    constexpr modint() noexcept : val{0} {}
    constexpr modint(long long x) noexcept : val((x %= mod) < 0 ? mod + x : x) {}
    constexpr long long value() const noexcept { return val; }
    constexpr modint &operator+=(const modint &other) noexcept { return (val += other.val) < mod ? 0 : val -= mod, *this; }
    constexpr modint &operator++() noexcept { return ++val, *this; }
    constexpr modint operator++(int) noexcept { modint t = *this; return ++val, t; }
    constexpr modint &operator-=(const modint &other) noexcept { return (val += mod - other.val) < mod ? 0 : val -= mod, *this; }
    constexpr modint &operator--() noexcept { return --val, *this; }
    constexpr modint operator--(int) noexcept { modint t = *this; return --val, t; }
    constexpr modint &operator*=(const modint &other) noexcept { return val = (long long)val * other.val % mod, *this; }
    constexpr modint &operator/=(const modint &other) noexcept { return *this *= inverse(other); }
    constexpr modint operator-() const noexcept { return modint(-val); }
    constexpr modint operator+(const modint &other) const noexcept { return modint(*this) += other; }
    constexpr modint operator-(const modint &other) const noexcept { return modint(*this) -= other; }
    constexpr modint operator*(const modint &other) const noexcept { return modint(*this) *= other; }
    constexpr modint operator/(const modint &other) const noexcept { return modint(*this) /= other; }
    constexpr bool operator==(const modint &other) const noexcept { return val == other.val; }
    constexpr bool operator!=(const modint &other) const noexcept { return val != other.val; }
    constexpr bool operator!() const noexcept { return !val; }
    template <class T> friend constexpr modint operator+(T x, modint y) noexcept { return modint(x) + y; }
    template <class T> friend constexpr modint operator-(T x, modint y) noexcept { return modint(x) - y; }
    template <class T> friend constexpr modint operator*(T x, modint y) noexcept { return modint(x) * y; }
    template <class T> friend constexpr modint operator/(T x, modint y) noexcept { return modint(x) / y; }
    friend constexpr modint inverse(const modint &other) noexcept
    {
        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) noexcept
    {
        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) noexcept { return s << other.val; }
    friend std::istream &operator>>(std::istream &s, modint &other) noexcept { long long val; other = modint{(s >> val, val)}; return s; }
}; // class modint
template <>
class modint<2>
{
    bool val;
  public:
    constexpr modint(bool x = false) noexcept : val{x} {}
    constexpr modint(int x) noexcept : val(x & 1) {}
    constexpr modint(long long x) noexcept : val(x & 1) {}
    constexpr bool value() const noexcept { return val; }
    constexpr modint &operator+=(const modint &other) noexcept { return val ^= other.val, *this; }
    constexpr modint &operator++() noexcept { return val = !val, *this; }
    constexpr modint operator++(int) noexcept { modint t = *this; return val = !val, t; }
    constexpr modint &operator-=(const modint &other) noexcept { return val ^= other.val, *this; }
    constexpr modint &operator--() noexcept { return val = !val, *this; }
    constexpr modint operator--(int) { modint t = *this; return val = !val, t; }
    constexpr modint &operator*=(const modint &other) noexcept { return val &= other.val, *this; }
    constexpr modint &operator/=(const modint &other) noexcept { return *this; }
    constexpr modint operator-() const noexcept { return *this; }
    constexpr modint operator+(const modint &other) const noexcept { return val != other.val; }
    constexpr modint operator-(const modint &other) const noexcept { return val != other.val; }
    constexpr modint operator*(const modint &other) const noexcept { return val && other.val; }
    constexpr modint operator/(const modint &other) const noexcept { return *this; }
    constexpr bool operator==(const modint &other) const noexcept { return val == other.val; }
    constexpr bool operator!=(const modint &other) const noexcept { return val != other.val; }
    constexpr bool operator!() const noexcept { return !val; }
    operator bool() const noexcept { return val; }
    template <class T> friend constexpr modint operator+(T x, modint y) noexcept { return modint(x) + y; }
    template <class T> friend constexpr modint operator-(T x, modint y) noexcept { return modint(x) - y; }
    template <class T> friend constexpr modint operator*(T x, modint y) noexcept { return modint(x) * y; }
    template <class T> friend constexpr modint operator/(T x, modint y) noexcept { return modint(x) / y; }
    friend constexpr modint inverse(const modint &other) noexcept { return other; }
    friend constexpr modint pow(const modint &other, long long exp) noexcept { return other; }
    friend std::ostream &operator<<(std::ostream &os, const modint &other) noexcept { return os << other.val; }
    friend std::istream &operator>>(std::istream &is, modint &other) noexcept { long long val; other.val = (is >> val, val & 1); return is; }
}; // class modint specialization
#endif

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

using mint = modint<1000000007>;
using namespace std;

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

    while(cin>>X>>Y>>Z)
    {
        mint ans,s{1};
        for(int k=X+Y+Z,f=1; k>=0; --k,f^=1)
        {
            mint 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