結果

問題 No.1126 SUM
ユーザー uw_yu1rabbituw_yu1rabbit
提出日時 2021-01-22 19:08:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 1,000 ms
コード長 3,178 bytes
コンパイル時間 1,815 ms
コンパイル使用メモリ 80,252 KB
実行使用メモリ 4,712 KB
最終ジャッジ日時 2023-08-27 14:58:42
合計ジャッジ時間 3,508 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,612 KB
testcase_01 AC 4 ms
4,684 KB
testcase_02 AC 4 ms
4,556 KB
testcase_03 AC 4 ms
4,684 KB
testcase_04 AC 4 ms
4,704 KB
testcase_05 AC 4 ms
4,704 KB
testcase_06 AC 4 ms
4,624 KB
testcase_07 AC 4 ms
4,536 KB
testcase_08 AC 4 ms
4,592 KB
testcase_09 AC 4 ms
4,532 KB
testcase_10 AC 4 ms
4,596 KB
testcase_11 AC 4 ms
4,592 KB
testcase_12 AC 4 ms
4,564 KB
testcase_13 AC 4 ms
4,684 KB
testcase_14 AC 4 ms
4,644 KB
testcase_15 AC 4 ms
4,620 KB
testcase_16 AC 4 ms
4,584 KB
testcase_17 AC 4 ms
4,712 KB
testcase_18 AC 4 ms
4,700 KB
testcase_19 AC 4 ms
4,636 KB
testcase_20 AC 3 ms
4,580 KB
testcase_21 AC 4 ms
4,536 KB
testcase_22 AC 4 ms
4,536 KB
testcase_23 AC 4 ms
4,608 KB
testcase_24 AC 3 ms
4,632 KB
testcase_25 AC 4 ms
4,712 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<cstdint>
#include<cstddef>
#include<vector>
//#include<atcoder/all>
//using namespace atcoder;
using namespace std;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using usize = size_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using i128 = __int128_t;
using u128 = __uint128_t;
using ld = long double;
template<typename T>
using vec = vector<T>;
#define rep(i, n) for (i64 i = 0; i < (i64)(n); ++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define len(hoge) (i64)((hoge).size())
using P = pair<i64,i64>;
constexpr i64 MOD = 1000000007;


template<i64 modulus>
class modcal {
public:
    i64 a;

    constexpr modcal(const i64 x = 0) noexcept: a(x % modulus) {}

    constexpr i64 &value() noexcept { return a; }

    constexpr const i64 &value() const noexcept { return a; }

    constexpr modcal operator+(const modcal rhs) const noexcept {
        return modcal(*this) += rhs;
    }

    constexpr modcal operator-(const modcal rhs) const noexcept {
        return modcal(*this) -= rhs;
    }

    constexpr modcal operator*(const modcal rhs) const noexcept {
        return modcal(*this) *= rhs;
    }

    constexpr modcal operator/(const modcal rhs) noexcept {
        return modcal(*this) /= rhs;
    }

    constexpr modcal &operator+=(const modcal rhs) noexcept {
        a += rhs.a;
        if (a >= modulus) {
            a -= modulus;
        }
        return *this;
    }

    constexpr modcal &operator-=(const modcal rhs) noexcept {
        if (a < rhs.a) {
            a += modulus;
        }
        a -= rhs.a;
        return *this;
    }

    constexpr modcal &operator*=(const modcal rhs) noexcept {
        a = a * rhs.a % modulus;
        return *this;
    }

    constexpr modcal &operator/=(modcal rhs) noexcept {
        i64 exp = modulus - 2;
        while (exp) {
            if (exp % 2) {
                *this *= rhs;
            }
            rhs *= rhs;
            exp /= 2;
        }
        return *this;
    }

    constexpr modcal<MOD> modpow(const modcal<MOD> &a, i64 n) {
        if (n == 0)
            return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1)
            t = t * a;
        return t;
    }

};

using modc = modcal<MOD>;

class com {
    vector <modc> fac, inv;
    i64 n;
public:
    com(i64 N) : fac(N + 1), inv(N + 1), n(N) {
        fac[0] = 1;
        for (i64 i = 1; i <= n; i++)fac[i] = fac[i - 1] * i;
        inv[n] = fac[n].modpow(fac[n], MOD - 2);
        for (i64 i = n; i >= 1; i--)inv[i - 1] = inv[i] * i;

    }

    modc combination(i64 n, i64 k) {
        if (k < 0 || k > n)return 0;
        return fac[n] * inv[k] * inv[n - k];
    }

    modc permutation(i64 n, i64 k) {
        if (k < 0 || k > n)return 0;
        return combination(n, k) * fac[k];
    }
};

int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    i64 n,m;
    cin >> n >> m;
    com f(100001);
    modc ans = 0;
    for(i32 i = n; i <= m; i++){
        ans += f.combination(i,n);
    }
    cout << ans.a << endl;
}
0