結果

問題 No.2149 Vanitas Vanitatum
ユーザー 👑 rin204rin204
提出日時 2022-12-26 00:49:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 4,030 bytes
コンパイル時間 2,343 ms
コンパイル使用メモリ 208,004 KB
実行使用メモリ 10,832 KB
最終ジャッジ日時 2023-08-12 16:42:54
合計ジャッジ時間 4,700 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,388 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 WA -
testcase_20 AC 16 ms
6,952 KB
testcase_21 WA -
testcase_22 AC 15 ms
6,952 KB
testcase_23 AC 13 ms
6,192 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 9 ms
5,176 KB
testcase_26 AC 27 ms
10,832 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 1 "A.cpp"
// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define endl "\n"

void print(){
	cout << '\n';
}

template <class Head, class... Tail>
void print(Head &&head, Tail &&... tail) {
	cout << head;
	if (sizeof...(Tail)) cout << ' ';
  	print(forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> &A){
	int n = A.size();
	for(int i = 0; i < n; i++){
		cout << A[i];
		if(i == n - 1) cout << '\n';
		else cout << ' ';
	}
}

template<typename T, typename S>
void prisep(vector<T> &A, S sep){
	int n = A.size();
	for(int i = 0; i < n; i++){
		cout << A[i];
		if(i == n - 1) cout << '\n';
		else cout << sep;
	}
}

template<typename T>
void print(vector<vector<T>> &A){
	for(auto &row: A) print(row);
}

template<typename T>
T sum(vector<T> &A){
	T tot = 0;
	for(auto a:A) tot += a;
	return tot;
}

#line 2 "Library/C++/math/modinv.hpp"

template<typename T>
T modinv(T a, T MOD){
    T b = MOD;
    T u = 1;
    T v = 0;
    while(b > 0){
        T t = a / b;
        a -= t * b;
        u -= t * v;
        swap(a, b);
        swap(u, v);
    }
    if(a != 1) return -1;
    if(u < 0) u += MOD;
    return u;
}
#line 3 "Library/C++/math/HookLengthFormula.hpp"

long long HookLengthFormula(vector<int> A, long long MOD = 998244353){
    int n = A.size();
    if(n == 0) return 1;
    long long tot = 0;
    for(auto a:A) tot += a;
    long long ans = 1;
    for(int i = 2; i <= tot; i++){
        ans *= (long long)i;
        ans %= MOD;
    }

    long long inv = 1;
    int r = n - 1;
    for(int i = 0; i < A[0]; i++){
        while(A[r] == i) r--;
        for(int j = r; j >= 0; j--){
            long long h = r - j + A[j] - i;
            inv *= h;
            inv %= MOD;
        }
    }
    return ans * modinv(inv, MOD) % MOD;
}
#line 3 "Library/C++/math/Combination.hpp"

#line 5 "Library/C++/math/Combination.hpp"
using namespace std;

struct Combination{
    int N;
    long long MOD;
    vector<long long> fact, invfact;
    Combination(int N, long long MOD = 998244353) : N(N), MOD(MOD){
        fact.resize(N + 1);
        invfact.resize(N + 1);
        fact[0] = 1;
        for(int i = 1; i <= N; i++){
            fact[i] = fact[i - 1] * i % MOD;
        }
        invfact[N] = modinv(fact[N], MOD);
        for(int i = N - 1; i >= 0; i--){
            invfact[i] = invfact[i + 1] * (i + 1) % MOD;
        }
    }

    long long nCk(int n, int k){
        assert(0 <= n && n <= N);
        if(k > n || k < 0) return 0;
        return (fact[n] * invfact[k] % MOD) * invfact[n - k] % MOD;
    }

    long long nPk(int n, int k){
        assert(0 <= n && n <= N);
        if(k > n || k < 0) return 0;
        return fact[n] * invfact[n - k] % MOD;
    }

    long long nHk(int n, int k){
        if(n == 0 && k == 0) return 1;
        return nCk(n + k - 1, k);
    }
};
#line 54 "A.cpp"

void solve(){
    int n;
	cin >> n;
	vector<int> A(n);
	for(int i = 0; i < n; i++) cin >> A[i];
	int tot = sum(A);
	if(tot & 1){
		print(0);
		return;
	}
	vector<int> P, Q;
	int t = 0;
	int b = 0;
	for(auto a:A){
		for(int i = 0; i < a - b; i++){
			if(t) P.push_back(0);
			else Q.push_back(0);
			t ^= 1;
		}
		b = a;
		if(t) P.push_back(1);
		else Q.push_back(1);
		t ^= 1;
	}

	int tp = sum(P);
	int tq = sum(Q);
	if(tp == tq){}
	else if(P.size() == Q.size() && tp + 1 == tq){}
	else if(tp == tq + 1){}
	else{
		print(0);
		return;
	}

	auto f=[](vector<int> &P) -> pair<ll, int> {
		vector<int> A;
		int x = 0;
		for(auto p:P){
			if(p == 0) x++;
			else A.push_back(x);
		}
		reverse(A.begin(), A.end());
		return {HookLengthFormula(A), sum(A)};
	};

	auto pp = f(P);
	auto qq = f(Q);
	Combination C(pp.second + qq.second);
	const ll MOD = 998244353;
	ll ans = (pp.first * qq.first % MOD) * C.nCk(pp.second + qq.second, pp.second) % MOD;
	print(ans);

}

int main(){
    cin.tie(0)->sync_with_stdio(0);
    int t;
    t = 1;
    // cin >> t;
    while(t--) solve();
	return 0;
}
0