結果

問題 No.1741 Arrays and XOR Procedure
ユーザー kwm_tkwm_t
提出日時 2021-11-12 22:17:14
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 124 ms / 2,000 ms
コード長 3,011 bytes
コンパイル時間 4,413 ms
コンパイル使用メモリ 234,304 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-25 19:14:26
合計ジャッジ時間 7,381 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
using mint = modint998244353;
const int mod = 998244353;
//const int INF = 1e9;
//const long long LINF = 1e18;
//const bool debug = false;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"
#define P pair<int,int>
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
mint dp[200005][2];
struct Lucas {
public:
	//pは素数
	Lucas(int p) :mod(p) { Init(); }
private:
	//下準備
	void Init() {
		CreateFact();
		CreateComb();
	}
	//comb計算
	void CreateComb() {
		comb.resize(mod);
		rep(i, mod) {
			comb[i].resize(mod);
			rep(j, mod) {
				if (i < j) {
					comb[i][j] = 0;
					continue;
				}
				comb[i][j] = (((fact[i] * ifact[j]) % mod) * ifact[i - j]) % mod;
			}
		}
	}
	//階乗計算
	void CreateFact() {
		fact.resize(mod);
		ifact.reserve(mod);
		fact[0] = 1;
		rep2(i, 1, mod) fact[i] = (fact[i - 1] * i) % mod;
		ifact[mod - 1] = inv(fact[mod - 1]);
		rrep2(i, 1, mod)ifact[i - 1] = (ifact[i] * i) % mod;
	}
	//逆元計算(x^(y - 2))
	long long inv(long long x) {
		int y = mod - 2;
		long long tmp = x;
		long long ret = 1;
		while (y > 0) {
			if (1 == y % 2) {
				ret *= tmp;
				ret %= mod;
			}
			y /= 2;
			tmp *= tmp;
			tmp %= mod;
		}
		return ret;
	}
public:
	//c(i,j)の計算
	int c(long long i, long long j) {
		if (i < j) return 0;
		long long ret = 1;
		while (i > 0) {
			int x = i % mod;
			int y = j % mod;
			ret *= comb[x][y];
			ret %= mod;
			i /= mod;
			j /= mod;
		}
		return ret;
	}
	//階乗デバッグ
	void debug() {
		rep(i, mod) cout << fact[i] << " ";
		cout << endl;
		rep(i, mod) cout << ifact[i] << " ";
		cout << endl;
	}
	//combデバッグ
	void debug2() {
		rep(i, mod) {
			rep(j, mod) cout << comb[i][j] << " ";
			cout << endl;
		}
	}
	//パスカルの三角形デバッグ
	void debug3() {
		rep(i, 10) {
			rep(j, i + 1) cout << c(i, j) << " ";
			cout << endl;
		}
	}
private:
	long long mod;
	vector<vector<long long>> comb;
	vector<long long>fact;
	vector<long long>ifact;
};
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	Lucas ls(2);
	int n; cin >> n;
	vector<int>a(n);
	rep(i, n)cin >> a[i];
	dp[0][0] = 1;
	rep(i, n) {
		if (-1 != a[i]) {
			int x = ls.c(n - 1, i);
			rep(j, 2) {
				int nj = (j + x * a[i]) % 2;
				dp[i + 1][nj] += dp[i][j];
			}
		}
		else {
			int x = ls.c(n - 1, i);
			rep(j, 2)rep(k, 2) {
				int nj = (j + x * k) % 2;
				dp[i + 1][nj] += dp[i][j];
			}
		}
	}
	cout << dp[n][1].val() << endl;
	return 0;
}
0