結果

問題 No.3117 Reversible Tile
ユーザー shobonvip
提出日時 2025-04-20 01:21:01
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 501 ms / 3,000 ms
コード長 1,875 bytes
コンパイル時間 4,793 ms
コンパイル使用メモリ 256,060 KB
実行使用メモリ 101,120 KB
最終ジャッジ日時 2025-04-20 01:21:15
合計ジャッジ時間 11,019 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

/**
	author:  shobonvip
	created: 2025.04.20 01:15:13
**/

#include<bits/stdc++.h>
using namespace std;

//* ATCODER
#include<atcoder/all>
using namespace atcoder;
typedef modint998244353 mint;
//*/

/* BOOST MULTIPRECISION
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
//*/

typedef long long ll;

#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)
#define all(v) v.begin(), v.end()

template <typename T> bool chmin(T &a, const T &b) {
	if (a <= b) return false;
	a = b;
	return true;
}

template <typename T> bool chmax(T &a, const T &b) {
	if (a >= b) return false;
	a = b;
	return true;
}

template <typename T> T max(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]);
	return ret;
}

template <typename T> T min(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]);
	return ret;
}

template <typename T> T sum(vector<T> &a){
	T ret = 0;
	for (int i=0; i<(int)a.size(); i++) ret += a[i];
	return ret;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n, m; cin >> n >> m;
	vector<int> a(n + 2);
	rep(i,0,n) {
		cin >> a[i+1];
	} 
	vector<int> b(n + 1);
	rep(i,0,n + 1) {
		b[i] = a[i] ^ a[i+1];
	}

	int ones = 0;

	rep(i,0,n + 1) {
		if (b[i] == 1) {
			ones++;
		}
	}

	vector dp(m + 1, vector<mint>(n + 2));
	dp[0][ones] = 1;

	mint inv2 = mint(2).inv();

	for (int i=0; i<m; i++) {
		for (int j=0; j<=n + 1; j++) {
			int c0 = n + 1 - j;
			int c1 = j;
			if (c0 >= 2) {
				dp[i+1][j+2] += dp[i][j] * c0 * (c0 - 1) * inv2;
			}
			if (c1 >= 2) {
				dp[i+1][j-2] += dp[i][j] * c1 * (c1 - 1) * inv2;
			}
			if (c0 >= 1 && c1 >= 1) {
				dp[i+1][j] += dp[i][j] * c0 * c1;
			}
		}
	}

	cout << dp[m][0].val() << endl;
}

0