結果

問題 No.802 だいたい等差数列
ユーザー veqccveqcc
提出日時 2019-03-18 18:13:35
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 129 ms / 2,000 ms
コード長 1,271 bytes
コンパイル時間 1,149 ms
コンパイル使用メモリ 101,820 KB
実行使用メモリ 50,508 KB
最終ジャッジ日時 2023-09-25 16:32:50
合計ジャッジ時間 6,590 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 106 ms
50,280 KB
testcase_01 AC 115 ms
50,220 KB
testcase_02 AC 107 ms
50,432 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 119 ms
50,380 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 119 ms
50,240 KB
testcase_07 AC 114 ms
50,280 KB
testcase_08 AC 115 ms
50,280 KB
testcase_09 AC 124 ms
50,212 KB
testcase_10 AC 118 ms
50,248 KB
testcase_11 AC 123 ms
50,312 KB
testcase_12 AC 119 ms
50,228 KB
testcase_13 AC 125 ms
50,252 KB
testcase_14 AC 126 ms
50,508 KB
testcase_15 AC 126 ms
50,256 KB
testcase_16 AC 128 ms
50,224 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 123 ms
50,496 KB
testcase_20 AC 123 ms
50,252 KB
testcase_21 AC 121 ms
50,288 KB
testcase_22 AC 120 ms
50,252 KB
testcase_23 AC 127 ms
50,316 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 115 ms
50,432 KB
testcase_26 AC 124 ms
50,308 KB
testcase_27 AC 115 ms
50,376 KB
testcase_28 AC 126 ms
50,220 KB
testcase_29 AC 125 ms
50,296 KB
testcase_30 AC 123 ms
50,428 KB
testcase_31 AC 129 ms
50,228 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 114 ms
50,252 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

const int MAX_N = 2000000;
const ll MOD = 1000000007LL;
ll inv[MAX_N], fac[MAX_N], fiv[MAX_N];
void COMinit() {
    inv[1] = fac[1] = fiv[1] = inv[0] = fac[0] = fiv[0] = 1;
    for (ll i = 2; i < MAX_N; i++) {
        fac[i] = fac[i - 1] * i % MOD; // n!
        inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD; // n^-1
        fiv[i] = fiv[i - 1] * inv[i] % MOD; // (n!)^-1
    }
}
ll com(ll n, ll k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * fiv[k] % MOD * fiv[n-k] % MOD;
}

int main() {
    cin.sync_with_stdio(false);
    cin.tie(0);

    ll n, m, d1, d2;
    cin >> n >> m >> d1 >> d2;

    ll d = d2 - d1;
    ll x = m - 1 - d1 * (n - 1);
    if (x < 0) {
        cout << 0 << '\n';
        return 0;
    }

    COMinit();

    ll ans = 0;
    for (ll i = 0; i < n; i++) {
        ll tmp = com(n-1, i) * com(x - i*(d+1) + n, n) % MOD;
        if (i % 2 == 0) ans += tmp;
        else ans += MOD - tmp;
        ans %= MOD;
    }

    cout << ans << "\n";
    return 0;
}
0