結果

問題 No.2058 Binary String
ユーザー 沙耶花沙耶花
提出日時 2022-08-26 22:22:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,032 bytes
コンパイル時間 5,576 ms
コンパイル使用メモリ 270,612 KB
実行使用メモリ 22,476 KB
最終ジャッジ日時 2024-04-22 00:28:55
合計ジャッジ時間 9,241 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
11,520 KB
testcase_01 AC 8 ms
6,144 KB
testcase_02 AC 8 ms
6,144 KB
testcase_03 AC 8 ms
5,888 KB
testcase_04 AC 8 ms
6,016 KB
testcase_05 AC 8 ms
6,016 KB
testcase_06 AC 91 ms
6,264 KB
testcase_07 TLE -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 4000000000000000001

struct combi{
	deque<mint> kaijou;
	deque<mint> kaijou_;
	
	combi(int n){
		kaijou.push_back(1);
		for(int i=1;i<=n;i++){
			kaijou.push_back(kaijou[i-1]*i);
		}
		
		mint b=kaijou[n].inv();
		
		kaijou_.push_front(b);
		for(int i=1;i<=n;i++){
			int k=n+1-i;
			kaijou_.push_front(kaijou_[0]*k);
		}
	}
	
	mint combination(int n,int r){
		if(r>n)return 0;
		mint a = kaijou[n]*kaijou_[r];
		a *= kaijou_[n-r];
		return a;
	}
	
	mint junretsu(int a,int b){
		mint x = kaijou_[a]*kaijou_[b];
		x *= kaijou[a+b];
		return x;
	}
	
	mint catalan(int n){
		return combination(2*n,n)/(n+1);
	}
	
};
int N,K;
array<array<vector<mint>,2>,2> merge(array<array<vector<mint>,2>,2> a,array<array<vector<mint>,2>,2> b){
	
	array<array<vector<mint>,2>,2> ret;
	rep(i,2){
		rep(j,2){
			ret[i][j] = vector<mint>(K+1,0);
		}
	}
	//cout<<ret[0][0].size()<<endl;
	rep(i,2){
		rep(j,2){
			rep(k,2){
				auto t = convolution(a[i][j],b[j][k]);
				rep(l,min(K+1,(int)t.size()))ret[i][k][l] += t[l];
			}
		}
	}
	return ret;
}

int main() {
	
	combi C(300000);
	
	//int N,K;
	cin>>N>>K;
	
	array<array<vector<mint>,2>,2> dp;
	dp[0][0] = vector<mint>(K+1,0);
	dp[0][0][0] = 1;
	dp[0][1] = dp[0][0];
	{
		vector<mint> t(K+1);
		for(int i=0;i<=K;i++){
			t[i] = C.kaijou_[i];
		}
		dp[1][0] = t;
		dp[1][1] = t;
	}
			
	array<array<vector<mint>,2>,2> cur;
	rep(i,2){
		rep(j,2)cur[i][j] = vector<mint>(K+1,0);
	}
	cur[0][0][0] = 1;
	
	rep(i,18){
		if((N>>i)&1){
			cur = merge(cur,dp);
		}
		dp = merge(dp,dp);
	}
	/*
	rep(i,2){
		rep(j,2){
			rep(k,cur[i][j].size())cout<<cur[i][j][k].val()<<',';
			cout<<endl;
		}
	}
	*/
	mint ans = 0;
	rep(i,2){
		rep(j,2){
			if(i!=0||j!=0)continue;
			if(cur[i][j].size()>K)ans += cur[i][j][K];
		}
	}
	rep(i,K)ans *= i+1;
	
	cout<<ans.val()<<endl;
	
    return 0;
}
0