結果

問題 No.802 だいたい等差数列
ユーザー kcvlexkcvlex
提出日時 2019-03-18 14:30:54
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,327 ms / 2,000 ms
コード長 3,387 bytes
コンパイル時間 2,902 ms
コンパイル使用メモリ 147,768 KB
実行使用メモリ 46,816 KB
最終ジャッジ日時 2023-09-25 10:54:13
合計ジャッジ時間 48,861 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,292 ms
23,308 KB
testcase_01 AC 1,291 ms
23,128 KB
testcase_02 AC 1,289 ms
23,132 KB
testcase_03 AC 1,288 ms
23,200 KB
testcase_04 AC 1,285 ms
23,360 KB
testcase_05 AC 1,299 ms
23,236 KB
testcase_06 AC 1,291 ms
23,296 KB
testcase_07 AC 1,290 ms
23,232 KB
testcase_08 AC 1,286 ms
23,124 KB
testcase_09 AC 1,284 ms
23,200 KB
testcase_10 AC 1,289 ms
23,180 KB
testcase_11 AC 1,287 ms
23,112 KB
testcase_12 AC 1,283 ms
23,232 KB
testcase_13 AC 1,291 ms
23,352 KB
testcase_14 AC 1,298 ms
26,188 KB
testcase_15 AC 1,304 ms
31,440 KB
testcase_16 AC 1,292 ms
24,148 KB
testcase_17 AC 1,286 ms
23,140 KB
testcase_18 AC 1,290 ms
23,232 KB
testcase_19 AC 1,293 ms
25,680 KB
testcase_20 AC 1,327 ms
46,780 KB
testcase_21 AC 1,324 ms
46,796 KB
testcase_22 AC 1,293 ms
23,232 KB
testcase_23 AC 1,300 ms
31,268 KB
testcase_24 AC 1,287 ms
23,384 KB
testcase_25 AC 1,286 ms
23,364 KB
testcase_26 AC 1,287 ms
23,384 KB
testcase_27 AC 1,289 ms
23,204 KB
testcase_28 AC 1,301 ms
30,940 KB
testcase_29 AC 1,324 ms
46,816 KB
testcase_30 AC 1,293 ms
23,228 KB
testcase_31 AC 1,291 ms
23,180 KB
testcase_32 AC 1,290 ms
23,384 KB
testcase_33 AC 1,293 ms
23,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define DEBUG_MODE
#define endl '\n'
#ifdef DEBUG_MODE
#define DEBUG(X) debug_func(X, #X)
#define DEBUG_ENDL endl << flush
#define DEBUG_SEPARATOR_LINE cout<<"=================\n"
#else
#define DEBUG(X) 0
#define DEBUG_ENDL 0
#define DEBUG_SEPARATOR_LINE 0
#endif
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
#define DEBUG_ENDL_S(S) ((S).size() ? "\n" : "") << flush;
template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T, typename U> using P = pair<T, U>;
using ll = int64_t;
using PLL = P<ll, ll>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename Head, typename... Tail> const Head& var_min(const Head &head, const Tail&... tail) { return min(head, var_min(tail...)); }
template <typename Head, typename... Tail> const Head& var_max(const Head &head, const Tail&... tail) { return max(head, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
void debug_func_preffix(const string &s) { if(s.size()) cout << s << " = "; }
template <typename T>
void debug_func(const T &t, const string &s = "") {
    debug_func_preffix(s);
    cout << t << DEBUG_ENDL_S(s);
}
template <typename T, typename U>
void debug_func(const P<T, U> &p, const string &s = "") {
    debug_func_preffix(s);
    cout << "(";
    debug_func(p.first);
    cout << ", ";
    debug_func(p.second);
    cout << ")" << DEBUG_ENDL_S(s);
}
template <typename T>
void debug_func(const V<T> &v, const string &s = "") {
    for(ll i = 0; i < v.size(); i++) {
        string t = s + "[" + to_string(i) + "]";
        debug_func(v[i], t);
    }
}

void init_io() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(30);
}

const ll MOD = 1e9 + 7;

class Combination {
private:
    template <typename T> using V = vector<ll>;
    ll N;
    ll MOD;
    V<ll> factv, rfactv;

public:
    /*
     * MOD must be a prime number.
     */
    Combination(ll N, ll MOD)
        : N(N), 
          MOD(MOD),
          factv(N + 1, 1),
          rfactv(N + 1)
    {
        for(ll i = 1; i <= N; i++) {
            factv[i] = factv[i - 1] * i % MOD;
        }
        for(ll i = 0; i <= N; i++) {
            rfactv[i] = pow(factv[i], MOD - 2);
        }
    }

    ll fact(ll n) {
        return factv[n];
    }

    ll rfact(ll n) {
        return rfactv[n];
    }

    ll pow(ll a, ll b) {
        return b ? (b & 1 ? a : 1) * pow(a * a % MOD, b / 2) % MOD : 1;
    }

    ll comb(ll n, ll k) {
        return factv[n] * rfactv[n - k] % MOD * rfactv[k] % MOD;
    }
};

Combination comb(1e6 + 3e5 + 10, MOD);
ll N, M, D1, D2;
ll distr;

ll calc(ll n) {
    if(n > N - 1) return 0;
    ll rest = distr - (D2 - D1 + 1) * n;
    if(rest < 0) return 0;
    ll ret = comb.comb(rest + N, N) * comb.comb(N - 1, n) % MOD;
    ((ret -= calc(n + 1)) += MOD) %= MOD;
    return ret;
}

int main() {
    init_io();
    cin >> N >> M >> D1 >> D2;
    distr = M - 1 - D1 * (N - 1);
    if(distr < 0) {
        cout << 0 << endl;
        return 0;
    }
    cout << calc(0) << endl;
    return 0;
}
0