結果

問題 No.1191 数え上げを愛したい(数列編)
ユーザー ktr216ktr216
提出日時 2020-08-22 17:38:14
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 76 ms / 2,000 ms
コード長 837 bytes
コンパイル時間 1,595 ms
コンパイル使用メモリ 165,176 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-23 11:30:16
合計ジャッジ時間 3,129 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
6,816 KB
testcase_01 AC 38 ms
6,944 KB
testcase_02 AC 36 ms
6,944 KB
testcase_03 AC 57 ms
6,940 KB
testcase_04 AC 49 ms
6,940 KB
testcase_05 AC 9 ms
6,940 KB
testcase_06 AC 75 ms
6,944 KB
testcase_07 AC 54 ms
6,940 KB
testcase_08 AC 55 ms
6,940 KB
testcase_09 AC 54 ms
6,944 KB
testcase_10 AC 5 ms
6,940 KB
testcase_11 AC 4 ms
6,944 KB
testcase_12 AC 68 ms
6,944 KB
testcase_13 AC 76 ms
6,944 KB
testcase_14 AC 60 ms
6,940 KB
testcase_15 AC 4 ms
6,940 KB
testcase_16 AC 4 ms
6,944 KB
testcase_17 AC 4 ms
6,940 KB
testcase_18 AC 4 ms
6,940 KB
testcase_19 AC 5 ms
6,944 KB
testcase_20 AC 5 ms
6,940 KB
testcase_21 AC 5 ms
6,940 KB
testcase_22 AC 27 ms
6,940 KB
testcase_23 AC 4 ms
6,940 KB
testcase_24 AC 4 ms
6,940 KB
testcase_25 AC 4 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

typedef long long ll;

ll mod_pow(ll x, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    ll N, M, A, B, MOD = 998244353;
    vector<ll> f(300001, 1);
    rep(i, 300000) {
        f[i + 1] = (f[i] * (i + 1)) % MOD;
    }
    cin >> N >> M >> A >> B;
    ll ans = 0;
    for (int i = 1; i <= M; i++) {
        ll x = min(i + B, M) - A * (N - 1) - i;
        if (x < 0) break;
        ll a = (f[x + N - 1] * mod_pow(f[N - 1], MOD - 2, MOD)) % MOD;
        a = (a * mod_pow(f[x], MOD - 2, MOD)) % MOD;
        ans = (ans + a) % MOD;
    }
    for (int i = 1; i <= N; i++) ans = (ans * i) % MOD;
    cout << ans << "\n";
}
0