結果

問題 No.1191 数え上げを愛したい(数列編)
ユーザー pes_magicpes_magic
提出日時 2020-08-22 15:24:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 19 ms / 2,000 ms
コード長 965 bytes
コンパイル時間 695 ms
コンパイル使用メモリ 70,256 KB
実行使用メモリ 15,136 KB
最終ジャッジ日時 2024-04-23 09:42:47
合計ジャッジ時間 1,896 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
14,976 KB
testcase_01 AC 18 ms
15,024 KB
testcase_02 AC 16 ms
14,920 KB
testcase_03 AC 18 ms
14,900 KB
testcase_04 AC 18 ms
14,976 KB
testcase_05 AC 17 ms
15,104 KB
testcase_06 AC 19 ms
14,976 KB
testcase_07 AC 16 ms
15,104 KB
testcase_08 AC 18 ms
14,976 KB
testcase_09 AC 17 ms
15,104 KB
testcase_10 AC 16 ms
14,916 KB
testcase_11 AC 17 ms
14,976 KB
testcase_12 AC 18 ms
14,976 KB
testcase_13 AC 18 ms
15,060 KB
testcase_14 AC 19 ms
15,100 KB
testcase_15 AC 16 ms
15,060 KB
testcase_16 AC 17 ms
14,892 KB
testcase_17 AC 17 ms
14,904 KB
testcase_18 AC 16 ms
14,976 KB
testcase_19 AC 17 ms
15,104 KB
testcase_20 AC 16 ms
15,136 KB
testcase_21 AC 16 ms
14,924 KB
testcase_22 AC 15 ms
14,928 KB
testcase_23 AC 17 ms
14,900 KB
testcase_24 AC 15 ms
14,928 KB
testcase_25 AC 15 ms
15,072 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

using namespace std;

const int MOD = 998244353;

int main(){
    const int maxSize = 500001;
    vector<long long> inv(maxSize);
    vector<long long> fact(maxSize);
    vector<long long> factInv(maxSize);
    for(int i=0;i<2;i++) inv[i] = fact[i] = factInv[i] = 1;
    for(int i=2;i<maxSize;i++){
        inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;
        fact[i] = fact[i-1] * i % MOD;
        factInv[i] = factInv[i-1] * inv[i] % MOD;
    }
    auto comb = [&](int n, int r){
        if(n < r || r < 0) return 0LL;
        return fact[n] * factInv[n-r] % MOD * factInv[r] % MOD;
    };
    long long N, M, A, B;
    while(cin >> N >> M >> A >> B){
        long long res = 0;
        for(int i=A;i<=B;i++){
            long long sel = i-(N-1)*A;
            if(sel < 0) continue;
            res += comb(sel+N-2, N-2) * fact[N] % MOD * (M-i) % MOD;
            res %= MOD;
        }
        cout << res << endl;
    }
}
0