結果

問題 No.1857 Gacha Addiction
ユーザー 👑 kmjpkmjp
提出日時 2022-02-25 23:24:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,411 ms / 6,000 ms
コード長 2,476 bytes
コンパイル時間 2,506 ms
コンパイル使用メモリ 211,720 KB
実行使用メモリ 22,220 KB
最終ジャッジ日時 2023-09-16 18:56:20
合計ジャッジ時間 45,115 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,948 KB
testcase_01 AC 4 ms
4,980 KB
testcase_02 AC 4 ms
4,980 KB
testcase_03 AC 4 ms
5,068 KB
testcase_04 AC 16 ms
5,320 KB
testcase_05 AC 16 ms
5,260 KB
testcase_06 AC 16 ms
5,308 KB
testcase_07 AC 16 ms
5,248 KB
testcase_08 AC 16 ms
5,516 KB
testcase_09 AC 388 ms
9,272 KB
testcase_10 AC 388 ms
9,616 KB
testcase_11 AC 389 ms
9,768 KB
testcase_12 AC 388 ms
9,328 KB
testcase_13 AC 387 ms
9,584 KB
testcase_14 AC 1,386 ms
20,220 KB
testcase_15 AC 1,394 ms
20,156 KB
testcase_16 AC 1,391 ms
20,132 KB
testcase_17 AC 1,393 ms
22,220 KB
testcase_18 AC 1,390 ms
21,280 KB
testcase_19 AC 1,411 ms
19,324 KB
testcase_20 AC 1,393 ms
19,204 KB
testcase_21 AC 1,393 ms
19,260 KB
testcase_22 AC 1,394 ms
19,192 KB
testcase_23 AC 1,390 ms
19,128 KB
testcase_24 AC 1,390 ms
19,120 KB
testcase_25 AC 1,389 ms
19,204 KB
testcase_26 AC 1,396 ms
19,132 KB
testcase_27 AC 1,393 ms
19,132 KB
testcase_28 AC 1,392 ms
19,184 KB
testcase_29 AC 1,397 ms
19,128 KB
testcase_30 AC 1,392 ms
19,124 KB
testcase_31 AC 1,399 ms
19,376 KB
testcase_32 AC 1,397 ms
19,280 KB
testcase_33 AC 1,395 ms
19,184 KB
testcase_34 AC 1,393 ms
19,272 KB
testcase_35 AC 1,392 ms
19,312 KB
testcase_36 AC 1,390 ms
19,124 KB
testcase_37 AC 1,390 ms
19,212 KB
testcase_38 AC 1,391 ms
19,128 KB
testcase_39 AC 377 ms
8,928 KB
testcase_40 AC 403 ms
9,792 KB
testcase_41 AC 535 ms
12,344 KB
testcase_42 AC 100 ms
6,916 KB
testcase_43 AC 1,139 ms
21,324 KB
testcase_44 AC 1,247 ms
19,204 KB
testcase_45 AC 3 ms
4,936 KB
testcase_46 AC 4 ms
4,928 KB
権限があれば一括ダウンロードができます

ソースコード

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;}
//-------------------------------------------------------


int N;
ll S;
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);
}

ll fact[202020];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	fact[0]=1;
	for(i=1;i<=200000;i++) fact[i]=fact[i-1]*i%mo;
	
	queue<vector<ll>> Q;
	cin>>N>>S;
	FOR(i,N) {
		cin>>x;
		Q.push({1LL,x*modpow(S)%mo});
	}
	while(Q.size()>1) {
		vector<ll> a=Q.front();
		Q.pop();
		vector<ll> b=Q.front();
		Q.pop();
		Q.push(MultPoly(a,b,1));
	}
	ll ret=0;
	FOR(i,N+1) ret+=fact[i]*Q.front()[i]%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