結果

問題 No.1191 数え上げを愛したい(数列編)
ユーザー 沙耶花沙耶花
提出日時 2020-08-22 13:53:51
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 1,378 bytes
コンパイル時間 2,266 ms
コンパイル使用メモリ 201,456 KB
実行使用メモリ 11,904 KB
最終ジャッジ日時 2024-04-23 08:18:34
合計ジャッジ時間 3,230 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 22 ms
11,648 KB
testcase_01 AC 23 ms
11,776 KB
testcase_02 AC 22 ms
11,776 KB
testcase_03 AC 23 ms
11,776 KB
testcase_04 AC 23 ms
11,776 KB
testcase_05 AC 22 ms
11,776 KB
testcase_06 AC 24 ms
11,776 KB
testcase_07 AC 23 ms
11,776 KB
testcase_08 AC 23 ms
11,648 KB
testcase_09 AC 23 ms
11,648 KB
testcase_10 AC 22 ms
11,648 KB
testcase_11 AC 22 ms
11,776 KB
testcase_12 AC 23 ms
11,648 KB
testcase_13 AC 23 ms
11,776 KB
testcase_14 AC 23 ms
11,776 KB
testcase_15 AC 22 ms
11,776 KB
testcase_16 AC 21 ms
11,648 KB
testcase_17 AC 21 ms
11,776 KB
testcase_18 AC 21 ms
11,776 KB
testcase_19 AC 21 ms
11,648 KB
testcase_20 AC 21 ms
11,776 KB
testcase_21 AC 22 ms
11,776 KB
testcase_22 AC 23 ms
11,648 KB
testcase_23 AC 22 ms
11,776 KB
testcase_24 AC 23 ms
11,904 KB
testcase_25 AC 25 ms
11,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000005

int beki(long long a,long long b,int M = modulo){
	int x = 1;
	while(b!=0){
		if(b&1){
			x=((long long)x*a)%M;
		}
		a=((long long)a*a)%M;
		b>>=1;
	}
	return x;
}


int gyakugen(int a){
	return beki(a,modulo-2);
}

struct combi{
	deque<int> kaijou;
	deque<int> kaijou_;
	
	combi(int n){
		kaijou.push_back(1);
		for(int i=1;i<=n;i++){
			kaijou.push_back(mod(kaijou[i-1]*i));
		}
		
		int b=gyakugen(kaijou[n]);
		
		kaijou_.push_front(b);
		for(int i=1;i<=n;i++){
			int k=n+1-i;
			kaijou_.push_front(mod(kaijou_[0]*k));
		}
	}
	
	int combination(int n,int r){
		if(r>n)return 0;
		int a = mod(kaijou[n]*kaijou_[r]);
		a=mod(a*kaijou_[n-r]);
		return a;
	}
	
	int junretsu(int a,int b){
		int x = mod(kaijou_[a]*kaijou_[b]);
		x=mod(x*kaijou[a+b]);
		return x;
	}
	
	int catalan(int n){
		return mod(combination(2*n,n)*gyakugen(n+1));
	}
	
};

int main(){
	
	long long N,M,A,B;
	cin>>N>>M>>A>>B;
	
	combi C(1000000);
	int ans = 0;
	for(long long i=1;i<=M;i++){
		long long  L = i;
		long long R = i+(N-1)*A;
		
		long long remain = M-R;
		remain = min(remain,((i+B)-R));
		if(remain<0)continue;
		ans = mod(ans + C.junretsu(remain,N-1));
		
	}
	
	for(int i=1;i<=N;i++)ans = mod(ans * i);
	
	cout<<ans<<endl;
	
	return 0;
}
0