結果

問題 No.1762 🐙🐄🌲
ユーザー leukocyteleukocyte
提出日時 2022-07-02 16:13:25
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 10 ms / 4,000 ms
コード長 1,074 bytes
コンパイル時間 1,565 ms
コンパイル使用メモリ 165,168 KB
実行使用メモリ 7,564 KB
最終ジャッジ日時 2023-08-18 07:14:26
合計ジャッジ時間 3,967 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,520 KB
testcase_01 AC 2 ms
5,768 KB
testcase_02 AC 5 ms
6,028 KB
testcase_03 AC 2 ms
5,536 KB
testcase_04 AC 2 ms
5,584 KB
testcase_05 AC 2 ms
5,572 KB
testcase_06 AC 2 ms
5,784 KB
testcase_07 AC 2 ms
5,636 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
5,524 KB
testcase_10 AC 2 ms
5,524 KB
testcase_11 AC 2 ms
5,532 KB
testcase_12 AC 2 ms
5,632 KB
testcase_13 AC 7 ms
6,764 KB
testcase_14 AC 8 ms
7,276 KB
testcase_15 AC 7 ms
6,916 KB
testcase_16 AC 9 ms
7,320 KB
testcase_17 AC 8 ms
7,032 KB
testcase_18 AC 9 ms
7,548 KB
testcase_19 AC 10 ms
7,564 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 9 ms
7,208 KB
testcase_27 AC 7 ms
6,900 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 5 ms
6,548 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 6 ms
6,548 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 6 ms
6,676 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 9 ms
7,372 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 AC 7 ms
7,248 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 7 ms
6,904 KB
testcase_43 AC 1 ms
4,380 KB
testcase_44 AC 6 ms
6,768 KB
testcase_45 AC 2 ms
4,380 KB
testcase_46 AC 8 ms
7,176 KB
testcase_47 AC 2 ms
4,376 KB
testcase_48 AC 9 ms
7,392 KB
testcase_49 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=5e5;
const int mod=998244353;
using arr=int[N+5];
arr fac,ifac;
int ksm(ll x,int tp,int s=1){
	for(;tp;x=x*x%mod,tp>>=1) if(tp&1) s=x*s%mod;
	return s;
}
void prep(int n){
	fac[0]=1;
	for(int i=1;i<=n;i++) fac[i]=1ll*fac[i-1]*i%mod;
	ifac[n]=ksm(fac[n],mod-2);
	for(int i=n;i;i--) ifac[i-1]=1ll*ifac[i]*i%mod;
}
int C(int n,int m){ return n<0||m<0||n<m?0:1ll*fac[n]*ifac[m]%mod*ifac[n-m]%mod; }
int inv(int n){ return 1ll*ifac[n]*fac[n-1]%mod; }
int n,p,m,r;
arr f;
int ans;
int main(){
	scanf("%d %d",&n,&p);
	m=(3*n+1)/4; r=n-m-1-7*p;
	if(n%4!=1||r<0){
		puts("0"); return 0;
	}
	if(n==1){
		puts("1"); return 0;
	}
	prep(n);
	ans=1ll*C(n,m)*C(m,p)%mod*fac[m-1]%mod*fac[n-m-1]%mod;
	ans=ksm(ifac[3],n-m,ans);
	ans=ksm(ifac[7],p,ans);
	f[0]=1;
	for(int i=1;i<=r;i++){
		ll s=0;
		for(int j=1;j<7&&j<=i;j++)
			s+=1ll*ifac[j-1]*f[i-j];
		s=s%mod*(m-p+1)%mod*inv(i)%mod;
		for(int j=1;j<7&&j<=i;j++)
			s-=1ll*ifac[j]*f[i-j];
		f[i]=s%mod;
	}
	printf("%lld\n",1ll*ans*(f[r]+mod)%mod);
	return 0;
}
0