結果

問題 No.802 だいたい等差数列
ユーザー drken1215drken1215
提出日時 2019-03-18 01:22:52
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,262 bytes
コンパイル時間 537 ms
コンパイル使用メモリ 65,736 KB
実行使用メモリ 52,836 KB
最終ジャッジ日時 2023-09-22 16:24:57
合計ジャッジ時間 10,372 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
52,796 KB
testcase_01 AC 60 ms
52,836 KB
testcase_02 AC 66 ms
52,568 KB
testcase_03 AC 64 ms
52,752 KB
testcase_04 AC 61 ms
52,604 KB
testcase_05 AC 63 ms
52,536 KB
testcase_06 AC 63 ms
52,568 KB
testcase_07 AC 63 ms
52,684 KB
testcase_08 AC 60 ms
52,604 KB
testcase_09 AC 61 ms
52,792 KB
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 AC 59 ms
52,596 KB
testcase_15 AC 57 ms
52,556 KB
testcase_16 AC 59 ms
52,536 KB
testcase_17 AC 55 ms
52,688 KB
testcase_18 AC 55 ms
52,608 KB
testcase_19 AC 58 ms
52,568 KB
testcase_20 AC 58 ms
52,612 KB
testcase_21 AC 58 ms
52,520 KB
testcase_22 RE -
testcase_23 AC 63 ms
52,608 KB
testcase_24 AC 60 ms
52,572 KB
testcase_25 AC 60 ms
52,572 KB
testcase_26 AC 63 ms
52,572 KB
testcase_27 RE -
testcase_28 AC 58 ms
52,668 KB
testcase_29 AC 59 ms
52,784 KB
testcase_30 AC 60 ms
52,596 KB
testcase_31 AC 57 ms
52,520 KB
testcase_32 AC 60 ms
52,520 KB
testcase_33 AC 57 ms
52,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

const int MAX = 2100000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAX; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
long long COM(int n, int k){
    if(n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}



long long N, M, D1, D2;
long long solve() {
    long long D = D2 - D1;
    long long x = M - 1 - D1 * (N-1);
    if (x < 0) return 0;

    long long res = 0;
    for (long long p = 0; p <= N-1; ++p) {
        long long tmp = COM(N-1, p) * COM(x - p*(D+1) + N, N) % MOD;
        if (p % 2 == 0) res += tmp;
        else res += MOD - tmp;
        res %= MOD;
    }
    return res;
}

int main() {
    COMinit();
    cin >> N >> M >> D1 >> D2;
    cout << solve() << endl;
}
0