結果

問題 No.2060 AND Sequence
ユーザー 沙耶花沙耶花
提出日時 2022-08-26 22:54:19
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 814 ms / 2,000 ms
コード長 1,427 bytes
コンパイル時間 4,945 ms
コンパイル使用メモリ 258,800 KB
実行使用メモリ 31,200 KB
最終ジャッジ日時 2024-04-22 00:59:36
合計ジャッジ時間 41,578 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 760 ms
31,104 KB
testcase_01 AC 783 ms
30,976 KB
testcase_02 AC 800 ms
31,104 KB
testcase_03 AC 773 ms
31,076 KB
testcase_04 AC 814 ms
30,976 KB
testcase_05 AC 765 ms
31,104 KB
testcase_06 AC 763 ms
30,976 KB
testcase_07 AC 782 ms
30,976 KB
testcase_08 AC 769 ms
31,104 KB
testcase_09 AC 767 ms
31,104 KB
testcase_10 AC 788 ms
30,976 KB
testcase_11 AC 793 ms
31,104 KB
testcase_12 AC 798 ms
30,976 KB
testcase_13 AC 794 ms
30,976 KB
testcase_14 AC 792 ms
30,976 KB
testcase_15 AC 794 ms
31,104 KB
testcase_16 AC 763 ms
30,976 KB
testcase_17 AC 777 ms
30,976 KB
testcase_18 AC 762 ms
31,052 KB
testcase_19 AC 766 ms
31,056 KB
testcase_20 AC 772 ms
31,104 KB
testcase_21 AC 776 ms
31,056 KB
testcase_22 AC 762 ms
31,064 KB
testcase_23 AC 771 ms
31,160 KB
testcase_24 AC 774 ms
30,972 KB
testcase_25 AC 771 ms
30,976 KB
testcase_26 AC 768 ms
31,200 KB
testcase_27 AC 761 ms
30,976 KB
testcase_28 AC 764 ms
31,060 KB
testcase_29 AC 769 ms
31,144 KB
testcase_30 AC 769 ms
31,104 KB
testcase_31 AC 763 ms
30,988 KB
testcase_32 AC 763 ms
31,104 KB
testcase_33 AC 776 ms
31,104 KB
testcase_34 AC 765 ms
30,976 KB
testcase_35 AC 776 ms
30,948 KB
testcase_36 AC 788 ms
31,104 KB
testcase_37 AC 791 ms
31,104 KB
testcase_38 AC 784 ms
30,960 KB
testcase_39 AC 785 ms
31,104 KB
testcase_40 AC 792 ms
31,180 KB
testcase_41 AC 758 ms
31,104 KB
testcase_42 AC 762 ms
31,156 KB
testcase_43 AC 767 ms
31,104 KB
testcase_44 AC 754 ms
31,104 KB
testcase_45 AC 782 ms
30,976 KB
権限があれば一括ダウンロードができます

ソースコード

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

mint dp[200005][31];

mint get(int N,int cur){
	int cnt = 0;
	rep(j,30){
		if((cur>>j)&1)cnt++;
	}
	return dp[N][cur];
}

int main() {
	
	long long N,M;
	cin>>N>>M;
	
	combi C(400000);
	rep(i,31)dp[0][i] = 1;
	
	rep(i,200003){
		rep(j,31){
			rep(k,31){
				if(j+k>30)break;
				dp[i+1][j+k] += dp[i][j] * C.junretsu(j,k);
			}
		}
	}
	
	mint ans = 0;
	ans += dp[N-1][__builtin_popcount(M)];
	int x = 0;
	for(int i=29;i>=0;i--){
		if((M>>i)&1){
			int y = i;
			rep(k,y+1){
				ans += dp[N-1][x+k] * C.combination(y,k);
			}
			
			x++;
		}
	}
	cout<<ans.val()<<endl;
    return 0;
}
0