結果

問題 No.1856 Mex Sum 2
ユーザー 👑 kmjpkmjp
提出日時 2022-02-26 00:35:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,929 bytes
コンパイル時間 2,529 ms
コンパイル使用メモリ 210,272 KB
実行使用メモリ 35,044 KB
最終ジャッジ日時 2023-09-16 20:34:10
合計ジャッジ時間 82,946 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 7 ms
4,384 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,384 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,384 KB
testcase_15 WA -
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 5 ms
4,380 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 6 ms
4,384 KB
testcase_23 AC 2 ms
4,384 KB
testcase_24 AC 3 ms
4,380 KB
testcase_25 AC 5 ms
4,384 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,384 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 AC 2,865 ms
32,656 KB
testcase_43 AC 2,545 ms
26,768 KB
testcase_44 AC 2,685 ms
29,284 KB
testcase_45 AC 2,815 ms
32,144 KB
testcase_46 AC 2,591 ms
26,860 KB
testcase_47 AC 2,670 ms
29,576 KB
testcase_48 AC 2,921 ms
33,564 KB
testcase_49 AC 2,932 ms
33,080 KB
testcase_50 AC 2,209 ms
22,672 KB
testcase_51 TLE -
testcase_52 AC 2,975 ms
34,380 KB
testcase_53 AC 2,984 ms
34,824 KB
testcase_54 TLE -
testcase_55 AC 2,999 ms
35,044 KB
testcase_56 TLE -
testcase_57 AC 2,995 ms
34,728 KB
testcase_58 AC 2,990 ms
34,840 KB
testcase_59 TLE -
testcase_60 AC 2,949 ms
34,756 KB
testcase_61 TLE -
testcase_62 AC 2,983 ms
34,936 KB
testcase_63 TLE -
testcase_64 AC 2,989 ms
34,776 KB
testcase_65 TLE -
testcase_66 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

const ll mo=998244353;

ll modpow(ll a, ll n = mo-2) {
	ll r=1;a%=mo;
	while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;
	return r;
}

template<class T> vector<T> fft(vector<T> v, bool rev=false) {
	int n=v.size(),i,j,m;
	
	for(i=0,j=1;j<n-1;j++) {
		for(int k=n>>1;k>(i^=k);k>>=1);
		if(i>j) swap(v[i],v[j]);
	}
	for(int m=2; m<=n; m*=2) {
		T wn=modpow(5,(mo-1)/m);
		if(rev) wn=modpow(wn);
		for(i=0;i<n;i+=m) {
			T w=1;
			for(int j1=i,j2=i+m/2;j2<i+m;j1++,j2++) {
				T t1=v[j1],t2=(ll)w*v[j2]%mo;
				v[j1]=t1+t2;
				v[j2]=t1+mo-t2;
				while(v[j1]>=mo) v[j1]-=mo;
				while(v[j2]>=mo) v[j2]-=mo;
				w=(ll)w*wn%mo;
			}
		}
	}
	if(rev) {
		ll rv = modpow(n);
		FOR(i,n) v[i]=(ll)v[i]*rv%mo;
	}
	return v;
}

template<class T> vector<T> MultPoly(vector<T> P,vector<T> Q,bool resize=false) {
	if(resize) {
		int maxind=0,pi=0,qi=0,i;
		int s=2;
		FOR(i,P.size()) if(norm(P[i])) pi=i;
		FOR(i,Q.size()) if(norm(Q[i])) qi=i;
		maxind=pi+qi+1;
		while(s*2<maxind) s*=2;
		P.resize(s*2);Q.resize(s*2);
		if(s<=16) { //fastpath
			vector<T> R(s*2);
			for(int x=0;x<2*s;x++) for(int y=0;x+y<2*s;y++) (R[x+y]+=P[x]*Q[y])%=mo;
			return R;
		}
	}
	P=fft(P), Q=fft(Q);
	for(int i=0;i<P.size();i++) P[i]=(ll)P[i]*Q[i]%mo;
	return fft(P,true);
}


int N,M;
vector<ll> V[2020];
const int NUM_=2021;
static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];

ll comb(ll N_, ll C_) {
	if(C_<0 || C_>N_) return 0;
	return factr[C_]*fact[N_]%mo*factr[N_-C_]%mo;
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	inv[1]=fact[0]=factr[0]=1;
	for (int i=2;i<=NUM_;++i) inv[i] = inv[mo % i] * (mo - mo / i) % mo;
	for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%mo, factr[i]=factr[i-1]*inv[i]%mo;

	cin>>N>>M;
	V[0]={1};
	V[0].resize(N+1);
	vector<ll> W;
	
	FOR(i,N+1) W.push_back(factr[i]);
	W[0]=0;
	
	ll ret=0;
	for(i=1;i<=min(N,M+1);i++) {
		vector<ll> X=V[i-1];
		FOR(j,X.size()) (X[j]*=factr[j])%=mo;
		X=MultPoly(X,W,1);
		X.resize(N+1);
		FOR(j,X.size()) (X[j]*=fact[j])%=mo;
		V[i]=X;
		
		ll pat=0;
		for(int len=1;len<=N;len++) {
			(pat+=V[i][len]*comb(N,len)%mo*modpow(M+1+M-i,N-len))%=mo;
		}
		(ret+=i*pat)%=mo;
	}
	
	cout<<ret%mo<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0