結果

問題 No.802 だいたい等差数列
ユーザー てんぷらてんぷら
提出日時 2024-04-13 14:35:16
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 52 ms / 2,000 ms
コード長 1,550 bytes
コンパイル時間 7,144 ms
コンパイル使用メモリ 336,720 KB
実行使用メモリ 35,744 KB
最終ジャッジ日時 2024-04-13 14:35:27
合計ジャッジ時間 10,131 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
27,796 KB
testcase_01 AC 34 ms
27,820 KB
testcase_02 AC 33 ms
27,792 KB
testcase_03 AC 33 ms
27,792 KB
testcase_04 AC 34 ms
27,972 KB
testcase_05 AC 36 ms
27,852 KB
testcase_06 AC 34 ms
27,852 KB
testcase_07 AC 33 ms
27,832 KB
testcase_08 AC 34 ms
27,816 KB
testcase_09 AC 34 ms
27,792 KB
testcase_10 AC 45 ms
34,964 KB
testcase_11 AC 44 ms
35,648 KB
testcase_12 AC 43 ms
34,684 KB
testcase_13 AC 44 ms
35,644 KB
testcase_14 AC 45 ms
34,848 KB
testcase_15 AC 45 ms
35,568 KB
testcase_16 AC 46 ms
35,296 KB
testcase_17 AC 46 ms
35,072 KB
testcase_18 AC 45 ms
35,744 KB
testcase_19 AC 45 ms
35,716 KB
testcase_20 AC 49 ms
35,584 KB
testcase_21 AC 52 ms
35,612 KB
testcase_22 AC 51 ms
35,572 KB
testcase_23 AC 47 ms
35,496 KB
testcase_24 AC 45 ms
35,724 KB
testcase_25 AC 44 ms
35,572 KB
testcase_26 AC 35 ms
27,972 KB
testcase_27 AC 46 ms
35,724 KB
testcase_28 AC 38 ms
30,064 KB
testcase_29 AC 48 ms
35,664 KB
testcase_30 AC 34 ms
27,816 KB
testcase_31 AC 34 ms
27,788 KB
testcase_32 AC 34 ms
27,860 KB
testcase_33 AC 41 ms
32,428 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/all>
#include <bits/stdc++.h>
using ll = long long;
using ull = unsigned long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
using namespace std;
using namespace atcoder;
using mint = modint1000000007;
const int inf = 1000000007;
const ll longinf = 1ll << 60;

namespace mod_util {
vector<mint> fact, invfact, inv;
void init(int n = 1 << 20) {
    fact.resize(n + 1);
    invfact.resize(n + 1);
    inv.resize(n + 1);
    fact[0] = 1;
    rep(i, n) fact[i + 1] = fact[i] * (i + 1);
    invfact[n] = fact[n].inv();
    rep(i, n) invfact[n - i - 1] = invfact[n - i] * (n - i);
    rep(i, n) inv[i + 1] = fact[i] * invfact[i + 1];
}

mint comb(int n, int k) {
    if(n < 0 || k < 0 || k > n)
        return 0;
    return fact[n] * invfact[k] * invfact[n - k];
}
} // namespace mod_util
using namespace mod_util;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    init(1 << 21);

    int n, m, d1, d2;
    cin >> n >> m >> d1 >> d2;
    vector<mint> bunshi(m + 1), bunbo(m + 1);
    rep(i, n) {
        ll p = ll(d1) * i + ll(d2 + 1) * (n - 1 - i);
        if(p > m)
            continue;
        if((n - 1 - i) % 2 == 0) {
            bunshi[p] = comb(n - 1, i);
        } else {
            bunshi[p] = -comb(n - 1, i);
        }
    }
    rep(i, m + 1) {
        bunbo[i] = comb(n + i, i);
    }
    mint ans = 0;
    rep(i, m) {
        ans += bunshi[i] * bunbo[m - 1 - i];
    }
    cout << ans.val() << endl;
    return 0;
}
0