結果

問題 No.1100 Boxes
ユーザー 👑 kmjpkmjp
提出日時 2020-06-27 00:44:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 179 ms / 2,000 ms
コード長 2,551 bytes
コンパイル時間 2,459 ms
コンパイル使用メモリ 207,740 KB
実行使用メモリ 20,116 KB
最終ジャッジ日時 2023-09-18 12:05:43
合計ジャッジ時間 7,326 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
12,856 KB
testcase_01 AC 18 ms
13,000 KB
testcase_02 AC 18 ms
12,708 KB
testcase_03 AC 18 ms
12,816 KB
testcase_04 AC 18 ms
12,924 KB
testcase_05 AC 18 ms
12,800 KB
testcase_06 AC 19 ms
12,808 KB
testcase_07 AC 19 ms
12,992 KB
testcase_08 AC 18 ms
12,744 KB
testcase_09 AC 18 ms
12,864 KB
testcase_10 AC 18 ms
12,924 KB
testcase_11 AC 18 ms
12,704 KB
testcase_12 AC 17 ms
12,996 KB
testcase_13 AC 18 ms
12,708 KB
testcase_14 AC 19 ms
12,768 KB
testcase_15 AC 19 ms
12,800 KB
testcase_16 AC 18 ms
12,808 KB
testcase_17 AC 19 ms
12,864 KB
testcase_18 AC 19 ms
12,852 KB
testcase_19 AC 22 ms
12,924 KB
testcase_20 AC 34 ms
13,268 KB
testcase_21 AC 89 ms
15,896 KB
testcase_22 AC 171 ms
19,864 KB
testcase_23 AC 90 ms
16,028 KB
testcase_24 AC 93 ms
16,068 KB
testcase_25 AC 94 ms
16,304 KB
testcase_26 AC 176 ms
19,964 KB
testcase_27 AC 171 ms
19,672 KB
testcase_28 AC 53 ms
14,168 KB
testcase_29 AC 173 ms
19,804 KB
testcase_30 AC 171 ms
19,472 KB
testcase_31 AC 55 ms
14,348 KB
testcase_32 AC 97 ms
16,292 KB
testcase_33 AC 179 ms
20,092 KB
testcase_34 AC 179 ms
19,992 KB
testcase_35 AC 18 ms
12,916 KB
testcase_36 AC 167 ms
20,116 KB
testcase_37 AC 19 ms
12,792 KB
testcase_38 AC 92 ms
16,020 KB
testcase_39 AC 176 ms
20,076 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#undef _P
#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 ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,K;
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;
}

ll pat[101010];

const int NUM_=400001;
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;
}
ll hcomb(int P_,int Q_) { return (P_==0&&Q_==0)?1:comb(P_+Q_-1,Q_);}

vector<ll> fft(vector<ll> 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) {
		ll wn=modpow(5,(mo-1)/m);
		if(rev) wn=modpow(wn);
		for(i=0;i<n;i+=m) {
			ll w=1;
			for(int j1=i,j2=i+m/2;j2<i+m;j1++,j2++) {
				ll t1=v[j1],t2=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=w*wn%mo;
			}
		}
	}
	if(rev) {
		ll rv = modpow(n);
		FOR(i,n) v[i]=v[i]*rv%mo;
	}
	return v;
}

vector<ll> MultPoly(vector<ll> P,vector<ll> 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);
	}
	P=fft(P), Q=fft(Q);
	for(int i=0;i<P.size();i++) P[i]=P[i]*Q[i]%mo;
	return fft(P,true);
}

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>>K;
	
	vector<ll> A(K+1),B(K+1);
	
	for(i=0;i<=K;i++) {
		A[i]=modpow(i,N)*factr[i]%mo;
		if(i%2) {
			B[i]=(mo-1)*factr[i]%mo;
		}
		else {
			B[i]=factr[i]%mo;
		}
	}
	auto C=MultPoly(A,B,true);
	
	ll ret=0;
	for(i=1;i<=K;i++) {
		if((K-i)%2) ret+=C[i]*comb(K,i)%mo*fact[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