結果

問題 No.1741 Arrays and XOR Procedure
ユーザー kwm_tkwm_t
提出日時 2021-11-12 22:17:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 131 ms / 2,000 ms
コード長 3,011 bytes
コンパイル時間 4,578 ms
コンパイル使用メモリ 231,396 KB
実行使用メモリ 5,688 KB
最終ジャッジ日時 2023-08-17 02:00:01
合計ジャッジ時間 8,277 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,912 KB
testcase_01 AC 3 ms
5,220 KB
testcase_02 AC 3 ms
5,072 KB
testcase_03 AC 131 ms
5,448 KB
testcase_04 AC 3 ms
4,936 KB
testcase_05 AC 127 ms
5,448 KB
testcase_06 AC 130 ms
5,428 KB
testcase_07 AC 131 ms
5,396 KB
testcase_08 AC 127 ms
5,428 KB
testcase_09 AC 114 ms
5,688 KB
testcase_10 AC 119 ms
5,408 KB
testcase_11 AC 92 ms
5,164 KB
testcase_12 AC 69 ms
5,148 KB
testcase_13 AC 110 ms
5,132 KB
testcase_14 AC 76 ms
5,196 KB
testcase_15 AC 105 ms
5,188 KB
testcase_16 AC 8 ms
5,096 KB
testcase_17 AC 37 ms
4,980 KB
testcase_18 AC 81 ms
5,096 KB
testcase_19 AC 7 ms
5,008 KB
testcase_20 AC 127 ms
5,504 KB
testcase_21 AC 99 ms
5,192 KB
testcase_22 AC 89 ms
5,176 KB
testcase_23 AC 33 ms
5,072 KB
testcase_24 AC 9 ms
4,948 KB
testcase_25 AC 126 ms
5,444 KB
testcase_26 AC 52 ms
5,004 KB
testcase_27 AC 7 ms
5,040 KB
testcase_28 AC 94 ms
5,096 KB
testcase_29 AC 107 ms
5,116 KB
testcase_30 AC 92 ms
5,336 KB
testcase_31 AC 7 ms
4,952 KB
testcase_32 AC 51 ms
4,916 KB
testcase_33 AC 64 ms
5,188 KB
testcase_34 AC 25 ms
4,968 KB
testcase_35 AC 4 ms
4,988 KB
testcase_36 AC 13 ms
5,256 KB
testcase_37 AC 50 ms
5,224 KB
testcase_38 AC 123 ms
5,364 KB
testcase_39 AC 41 ms
5,008 KB
testcase_40 AC 4 ms
4,920 KB
testcase_41 AC 21 ms
4,912 KB
testcase_42 AC 7 ms
5,040 KB
testcase_43 AC 3 ms
5,024 KB
権限があれば一括ダウンロードができます

ソースコード

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