結果

問題 No.1191 数え上げを愛したい(数列編)
ユーザー otoshigootoshigo
提出日時 2023-02-24 13:40:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 1,218 bytes
コンパイル時間 683 ms
コンパイル使用メモリ 77,564 KB
実行使用メモリ 26,516 KB
最終ジャッジ日時 2023-10-09 22:57:08
合計ジャッジ時間 3,758 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
26,360 KB
testcase_01 AC 34 ms
26,212 KB
testcase_02 AC 33 ms
26,368 KB
testcase_03 AC 33 ms
26,400 KB
testcase_04 AC 32 ms
26,424 KB
testcase_05 AC 32 ms
26,240 KB
testcase_06 AC 34 ms
26,480 KB
testcase_07 AC 33 ms
26,464 KB
testcase_08 AC 33 ms
26,516 KB
testcase_09 AC 32 ms
26,452 KB
testcase_10 AC 32 ms
26,504 KB
testcase_11 AC 33 ms
26,364 KB
testcase_12 AC 32 ms
26,356 KB
testcase_13 AC 35 ms
26,292 KB
testcase_14 AC 34 ms
26,476 KB
testcase_15 AC 30 ms
26,432 KB
testcase_16 AC 31 ms
26,500 KB
testcase_17 AC 32 ms
26,444 KB
testcase_18 AC 30 ms
26,332 KB
testcase_19 AC 29 ms
26,476 KB
testcase_20 AC 32 ms
26,496 KB
testcase_21 AC 31 ms
26,492 KB
testcase_22 AC 31 ms
26,220 KB
testcase_23 AC 31 ms
26,448 KB
testcase_24 AC 31 ms
26,500 KB
testcase_25 AC 32 ms
26,300 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}
template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}

const int MAX=1e6,MOD=998244353;
vector<ll>fac(MAX),finv(MAX),inv(MAX);

void set_fac(){
    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;
    }
}

ll cmb(int n,int r){
    if (r<0||n<r)return 0;
    return fac[n]*(finv[r]*finv[n-r]%MOD)%MOD;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    set_fac();
    ll n,m,a,b;
    cin>>n>>m>>a>>b;
    if(a*(n-1)>b){
        cout<<0<<"\n";
        return 0;
    }
    m-=a*(n-1);
    b-=a*(n-1);
    ll ans=0;
    for(int i=0;i<=b;i++){
        ll cnt=cmb(i+n-2,i)*(m-i)%MOD;
        ans+=cnt;
        ans%=MOD;
    }
    rep(i,n)ans=ans*(i+1)%MOD;
    cout<<ans<<"\n";
}
0