結果

問題 No.802 だいたい等差数列
ユーザー drken1215drken1215
提出日時 2019-03-18 01:24:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,263 bytes
コンパイル時間 2,174 ms
コンパイル使用メモリ 65,532 KB
実行使用メモリ 261,408 KB
最終ジャッジ日時 2023-09-22 16:25:49
合計ジャッジ時間 11,746 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 510 ms
261,220 KB
testcase_01 AC 480 ms
261,144 KB
testcase_02 AC 487 ms
261,168 KB
testcase_03 AC 488 ms
261,232 KB
testcase_04 AC 489 ms
261,280 KB
testcase_05 AC 493 ms
261,408 KB
testcase_06 AC 496 ms
261,148 KB
testcase_07 AC 487 ms
261,208 KB
testcase_08 AC 493 ms
261,152 KB
testcase_09 AC 498 ms
261,092 KB
testcase_10 TLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
権限があれば一括ダウンロードができます

ソースコード

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 = 11000000;
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