結果

問題 No.1191 数え上げを愛したい(数列編)
ユーザー RhoRho
提出日時 2020-07-31 22:31:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 104 ms / 2,000 ms
コード長 913 bytes
コンパイル時間 1,504 ms
コンパイル使用メモリ 165,496 KB
実行使用メモリ 13,012 KB
最終ジャッジ日時 2023-09-21 00:57:19
合計ジャッジ時間 5,373 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 103 ms
12,716 KB
testcase_01 AC 104 ms
12,716 KB
testcase_02 AC 102 ms
12,824 KB
testcase_03 AC 102 ms
12,776 KB
testcase_04 AC 103 ms
12,748 KB
testcase_05 AC 103 ms
12,824 KB
testcase_06 AC 104 ms
12,708 KB
testcase_07 AC 103 ms
12,764 KB
testcase_08 AC 102 ms
12,704 KB
testcase_09 AC 103 ms
12,832 KB
testcase_10 AC 103 ms
12,764 KB
testcase_11 AC 103 ms
12,768 KB
testcase_12 AC 103 ms
12,724 KB
testcase_13 AC 103 ms
12,708 KB
testcase_14 AC 104 ms
12,892 KB
testcase_15 AC 102 ms
12,728 KB
testcase_16 AC 102 ms
13,012 KB
testcase_17 AC 102 ms
12,712 KB
testcase_18 AC 102 ms
12,708 KB
testcase_19 AC 102 ms
12,888 KB
testcase_20 AC 102 ms
12,776 KB
testcase_21 AC 102 ms
12,720 KB
testcase_22 AC 103 ms
12,776 KB
testcase_23 AC 103 ms
12,712 KB
testcase_24 AC 102 ms
12,716 KB
testcase_25 AC 102 ms
12,720 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define vi vector<int>
#define all(a) a.begin(),a.end()
typedef pair<int,int> P;
const long long mod=998244353;
const long long inf=1ll<<61;
int kj[600006],kji[600006];
int modpow(int a,int x){
  int res=1;
  while(x){
    if(x&1)res=res*a%mod;
    a=a*a%mod;
    x>>=1;
  }
  return res;
}
void setkj(){
  kj[0]=kji[0]=1;
  for(int i=1;i<=600002;i++){
    kj[i]=kj[i-1]*i%mod;
    kji[i]=modpow(kj[i],mod-2);
  }
}
int comb(int r,int c){
  if(r<c)return 0;
  return kj[r]*kji[c]%mod*kji[r-c]%mod;
}

signed main(){
  setkj();
  int n,m,a,b;cin>>n>>m>>a>>b;
  int ans=0;
  for(int i=0;i<=b;i++){
    int d=i-(n-1)*a;
    if(d<0)continue;
    ans+=comb(n-1+d-1,d)*(m-i)%mod;
    ans%=mod;
  } 
  cout<<ans*kj[n]%mod<<endl;
  assert(2<=n&&n<=100000);
  assert(2<=m&&m<=300000);
  assert(1<=a&&a<=b&&b<=m-1);
}
0