結果

問題 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
コンパイル時間 632 ms
コンパイル使用メモリ 70,468 KB
実行使用メモリ 14,784 KB
最終ジャッジ日時 2023-08-05 12:32:16
合計ジャッジ時間 2,177 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
14,676 KB
testcase_01 AC 17 ms
14,784 KB
testcase_02 AC 15 ms
14,588 KB
testcase_03 AC 15 ms
14,632 KB
testcase_04 AC 17 ms
14,652 KB
testcase_05 AC 16 ms
14,564 KB
testcase_06 AC 19 ms
14,748 KB
testcase_07 AC 16 ms
14,768 KB
testcase_08 AC 16 ms
14,476 KB
testcase_09 AC 15 ms
14,520 KB
testcase_10 AC 15 ms
14,528 KB
testcase_11 AC 15 ms
14,480 KB
testcase_12 AC 17 ms
14,512 KB
testcase_13 AC 17 ms
14,720 KB
testcase_14 AC 18 ms
14,704 KB
testcase_15 AC 15 ms
14,632 KB
testcase_16 AC 15 ms
14,504 KB
testcase_17 AC 15 ms
14,576 KB
testcase_18 AC 15 ms
14,532 KB
testcase_19 AC 15 ms
14,716 KB
testcase_20 AC 15 ms
14,568 KB
testcase_21 AC 15 ms
14,708 KB
testcase_22 AC 14 ms
14,636 KB
testcase_23 AC 15 ms
14,588 KB
testcase_24 AC 15 ms
14,520 KB
testcase_25 AC 16 ms
14,640 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