結果

問題 No.802 だいたい等差数列
ユーザー drken1215drken1215
提出日時 2019-03-18 01:26:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 481 ms / 2,000 ms
コード長 1,275 bytes
コンパイル時間 3,192 ms
コンパイル使用メモリ 65,084 KB
実行使用メモリ 261,324 KB
最終ジャッジ日時 2023-09-22 16:26:20
合計ジャッジ時間 18,552 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 471 ms
261,204 KB
testcase_01 AC 471 ms
261,264 KB
testcase_02 AC 465 ms
261,064 KB
testcase_03 AC 473 ms
261,080 KB
testcase_04 AC 478 ms
261,084 KB
testcase_05 AC 477 ms
261,040 KB
testcase_06 AC 461 ms
261,044 KB
testcase_07 AC 474 ms
261,108 KB
testcase_08 AC 466 ms
261,100 KB
testcase_09 AC 469 ms
261,108 KB
testcase_10 AC 471 ms
261,044 KB
testcase_11 AC 463 ms
261,056 KB
testcase_12 AC 472 ms
261,192 KB
testcase_13 AC 469 ms
261,296 KB
testcase_14 AC 472 ms
261,132 KB
testcase_15 AC 457 ms
261,324 KB
testcase_16 AC 463 ms
261,152 KB
testcase_17 AC 459 ms
261,052 KB
testcase_18 AC 455 ms
261,216 KB
testcase_19 AC 464 ms
261,156 KB
testcase_20 AC 459 ms
261,152 KB
testcase_21 AC 470 ms
261,148 KB
testcase_22 AC 464 ms
261,260 KB
testcase_23 AC 468 ms
261,056 KB
testcase_24 AC 455 ms
261,152 KB
testcase_25 AC 463 ms
261,252 KB
testcase_26 AC 458 ms
261,300 KB
testcase_27 AC 462 ms
261,112 KB
testcase_28 AC 481 ms
261,200 KB
testcase_29 AC 470 ms
261,080 KB
testcase_30 AC 475 ms
261,300 KB
testcase_31 AC 476 ms
261,108 KB
testcase_32 AC 469 ms
261,108 KB
testcase_33 AC 471 ms
261,132 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 = 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(long long n, long long 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