提出 #61233579


ソースコード 拡げる

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
const ll mod=1e9+7;
const int N=2e7+5;
const int iu=2e7+3;
ll f[N],inf[N];
ll pw(ll x,ll y){
	if(y==0) return 1;
	if(y%2) return x*pw(x,y-1)%mod;
	ll res=pw(x,y/2);
	return res*res%mod;
}
ll C(int x,int y){
	if(y>x|| y<0) return 0;
	return f[x]*inf[y]%mod*inf[x-y]%mod;
}
ll n,a,b;
int main(){
	ios::sync_with_stdio(false);cin.tie(0);
	f[0]=1;
	for(int i=1; i<=iu ;i++) f[i]=f[i-1]*i%mod;
	inf[iu]=pw(f[iu],mod-2);
	for(int i=iu; i>=1 ;i--) inf[i-1]=inf[i]*i%mod;
	cin >> n >> a >> b;
	ll d=n-a-b;
	ll ans=0;
	for(int i=1; i<=b ;i++){//cycle has i continuous A-blocks and i B-blocks
		ll all=0,end_a=0;
		{
			ll w1=0,w2=0,w3=0;
			w1=C(a-1,i-1)*C(b-1,i-1)%mod;
			w2=C(a-1,i-1)*C(b-1,i)%mod;
			w3=C(a-1,i)*C(b-1,i-1)%mod;
			ll dv=f[a+b-1]*inf[a+b]%mod;
			end_a=(w1+w2+w3+w1)%mod*(a-b)%mod*dv%mod;//out of many cycles this amount catalan
		}
		{
			ll w1=0,w2=0,w3=0;
			w1=C(a,i-1)*C(b-1,i-1)%mod;
			w2=C(a,i-1)*C(b-1,i)%mod;
			w3=C(a,i)*C(b-1,i-1)%mod;
			ll dv=f[a+b]*inf[a+b+1]%mod;
			all=(w1+w2+w3+w1)%mod*(a-b+1)%mod*dv%mod;//out of many cycles this amount catalan
			//cout << i << ' ' << w1 << ' ' << w2 << ' ' << w3 << endl;
		}
		
		all=(all+mod-end_a)%mod;
		//cout << i << ' ' << end_a << ' ' << all << endl;
		ll nd=d-(a+b)+2*i;
		if(nd>=0){
			ans=(ans+all*C(nd+a+b,a+b))%mod;
		}
		++nd;
		if(nd>=0){
			ans=(ans+end_a*C(nd+a+b,a+b))%mod;
		}
	}
	cout << ans << '\n';
}

提出情報

提出日時
問題 C - No Streak
ユーザ mulgokizary
言語 C++ 20 (gcc 12.2)
得点 1000
コード長 1553 Byte
結果 AC
実行時間 577 ms
メモリ 316124 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 1000 / 1000
結果
AC × 3
AC × 43
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_n_small_00.txt, 01_n_small_01.txt, 01_n_small_02.txt, 01_n_small_03.txt, 01_n_small_04.txt, 01_n_small_05.txt, 01_n_small_06.txt, 01_n_small_07.txt, 01_n_small_08.txt, 01_n_small_09.txt, 01_n_small_10.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 02_random_11.txt, 02_random_12.txt, 02_random_13.txt, 02_random_14.txt, 02_random_15.txt, 02_random_16.txt, 02_random_17.txt, 02_random_18.txt, 02_random_19.txt, 03_no_draw_00.txt, 03_no_draw_01.txt, 03_no_draw_02.txt, 04_b_eq_1_00.txt, 04_b_eq_1_01.txt, 04_b_eq_1_02.txt, 05_fft_killer_00.txt, 05_fft_killer_01.txt, 05_fft_killer_02.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 269 ms 315892 KiB
00_sample_01.txt AC 270 ms 315864 KiB
00_sample_02.txt AC 312 ms 315996 KiB
01_n_small_00.txt AC 269 ms 315892 KiB
01_n_small_01.txt AC 271 ms 315992 KiB
01_n_small_02.txt AC 269 ms 315928 KiB
01_n_small_03.txt AC 269 ms 316052 KiB
01_n_small_04.txt AC 269 ms 316112 KiB
01_n_small_05.txt AC 270 ms 315992 KiB
01_n_small_06.txt AC 269 ms 316056 KiB
01_n_small_07.txt AC 269 ms 315996 KiB
01_n_small_08.txt AC 269 ms 315976 KiB
01_n_small_09.txt AC 270 ms 315896 KiB
01_n_small_10.txt AC 269 ms 315996 KiB
02_random_00.txt AC 381 ms 315856 KiB
02_random_01.txt AC 368 ms 315968 KiB
02_random_02.txt AC 300 ms 315976 KiB
02_random_03.txt AC 450 ms 315996 KiB
02_random_04.txt AC 480 ms 315956 KiB
02_random_05.txt AC 372 ms 315892 KiB
02_random_06.txt AC 272 ms 315852 KiB
02_random_07.txt AC 373 ms 315956 KiB
02_random_08.txt AC 271 ms 315980 KiB
02_random_09.txt AC 338 ms 315900 KiB
02_random_10.txt AC 271 ms 315996 KiB
02_random_11.txt AC 372 ms 316120 KiB
02_random_12.txt AC 384 ms 316048 KiB
02_random_13.txt AC 345 ms 315996 KiB
02_random_14.txt AC 337 ms 315972 KiB
02_random_15.txt AC 426 ms 315856 KiB
02_random_16.txt AC 310 ms 316120 KiB
02_random_17.txt AC 293 ms 315992 KiB
02_random_18.txt AC 281 ms 315912 KiB
02_random_19.txt AC 285 ms 315892 KiB
03_no_draw_00.txt AC 341 ms 315892 KiB
03_no_draw_01.txt AC 543 ms 315928 KiB
03_no_draw_02.txt AC 577 ms 315996 KiB
04_b_eq_1_00.txt AC 269 ms 315916 KiB
04_b_eq_1_01.txt AC 268 ms 315912 KiB
04_b_eq_1_02.txt AC 270 ms 316120 KiB
05_fft_killer_00.txt AC 548 ms 315924 KiB
05_fft_killer_01.txt AC 534 ms 316124 KiB
05_fft_killer_02.txt AC 501 ms 315932 KiB