結果

問題 No.1100 Boxes
ユーザー 沙耶花沙耶花
提出日時 2020-09-23 17:02:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,903 bytes
コンパイル時間 4,038 ms
コンパイル使用メモリ 245,740 KB
実行使用メモリ 29,892 KB
最終ジャッジ日時 2023-09-10 07:17:41
合計ジャッジ時間 12,173 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
11,480 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 3 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 4 ms
4,376 KB
testcase_19 AC 30 ms
4,380 KB
testcase_20 AC 72 ms
4,376 KB
testcase_21 AC 91 ms
4,380 KB
testcase_22 AC 787 ms
8,236 KB
testcase_23 AC 729 ms
9,352 KB
testcase_24 AC 1,507 ms
15,700 KB
testcase_25 TLE -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/convolution>
#include <atcoder/modint>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000000000000

struct FPS:vector<mint>{
	using vector<mint>::vector;
	
	FPS(const vector<mint> &x):vector<mint>(x){
	}
	
	FPS pow(long long n,int maxDegree = -1){
		if(maxDegree==-1)maxDegree = (*this).size() - 1;
		FPS now = (*this);
		FPS ret(1,1);
		
		while(n!=0){
			if(n&1){
				ret *= now;
			}
			n>>=1;
			if(n==0)break;
			now *= now;
			while(now.size()>maxDegree+1)now.pop_back();
			while(ret.size()>maxDegree+1)ret.pop_back();
		}
		while(ret.size()>maxDegree+1)ret.pop_back();
		
		return ret;
	}
	
	FPS inv(int maxDegree = -1){
		if(maxDegree==-1)maxDegree = (*this).size() - 1;
		
		FPS ret(1,(*this)[0].inv());
		int m = 1;
		while(m<maxDegree+1){
			ret = ret*2 - ret*ret*(*this);
			m *= 2;
			while(ret.size()>m)ret.pop_back();
		}

		while(ret.size()>maxDegree+1)ret.pop_back();
		
		return ret;
	}
	
	FPS &operator+=(mint another){
		*this += FPS(1,another);
		return (*this);
	}
	
	FPS operator+(mint another)const{
		return (FPS(*this)+=another);
	}
	
	FPS &operator+=(const FPS &another){
		if((*this).size()<another.size())(*this).resize(another.size(),0);
		rep(i,min((int)(*this).size(),(int)another.size())){
			(*this)[i] += another[i];
		}
		return (*this);
	}
	
	FPS operator+(const FPS &another)const{
		return (FPS(*this)+=another);
	}
	
	FPS operator-(){
		return (FPS(*this)*=-1);
	}
	
	FPS &operator-=(mint another){
		*this -= FPS(1,another);
		return (*this);
	}
	
	FPS operator-(mint another)const{
		return (FPS(*this)-=another);
	}
	
	FPS &operator-=(const FPS &another){
		if((*this).size()<another.size())(*this).resize(another.size(),0);
		rep(i,min((int)(*this).size(),(int)another.size())){
			(*this)[i] -= another[i];
		}
		return (*this);
	}
	
	FPS operator-(const FPS &another)const{
		return (FPS(*this)-=another);
	}
	
	FPS &operator*=(mint another){
		rep(i,(*this).size()){
			(*this)[i] *= another;
		}
		return (*this);
	}
	
	FPS operator*(mint another)const{
		return (FPS(*this)*=another);
	}
	
	FPS &operator*=(const FPS &another){
		FPS temp(convolution((*this),another));
		(*this) = temp;
		return (*this);
	}
	
	FPS operator*(const FPS &another)const{
		return (FPS(*this)*=another);
	}
	
	void show(){
		rep(i,(*this).size()){
			cout<<(*this)[i].val()<<',';
		}
		cout<<endl;
	}
	
};

int main(){

	int N,K;
	cin>>N>>K;
	
	FPS F(N+1,1);
	
	for(int i=1;i<=N;i++){
		F[i] = F[i-1] * i;
	}
	
	F.back() = F.back().inv();
	
	for(int i=N-1;i>=1;i--){
		F[i] = F[i+1] * (i+1);
	}
	
	FPS ans = F.pow(K,N);
	
	F -= 1;
	F = -F + 1;
		
	if(K&1){
		ans += F.pow(K,N);
	}
	else{
		ans -= F.pow(K,N);
	}
	
	mint Ans = ans[N];
	Ans /= 2;
	
	for(int i=1;i<=N;i++)Ans *= i;
	
	cout<<Ans.val()<<endl;

	return 0;
}
0