結果

問題 No.2149 Vanitas Vanitatum
ユーザー 👑 NachiaNachia
提出日時 2022-12-06 00:37:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 3,237 bytes
コンパイル時間 1,134 ms
コンパイル使用メモリ 89,900 KB
実行使用メモリ 18,904 KB
最終ジャッジ日時 2023-08-02 22:17:17
合計ジャッジ時間 3,088 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
18,800 KB
testcase_01 AC 27 ms
18,628 KB
testcase_02 AC 26 ms
18,784 KB
testcase_03 AC 26 ms
18,376 KB
testcase_04 AC 26 ms
18,672 KB
testcase_05 AC 25 ms
18,520 KB
testcase_06 AC 25 ms
18,524 KB
testcase_07 AC 26 ms
18,748 KB
testcase_08 AC 27 ms
18,568 KB
testcase_09 AC 26 ms
18,372 KB
testcase_10 AC 27 ms
18,904 KB
testcase_11 AC 26 ms
18,760 KB
testcase_12 AC 29 ms
18,592 KB
testcase_13 AC 27 ms
18,748 KB
testcase_14 AC 31 ms
18,676 KB
testcase_15 AC 29 ms
18,516 KB
testcase_16 AC 26 ms
18,744 KB
testcase_17 AC 28 ms
18,764 KB
testcase_18 AC 30 ms
18,740 KB
testcase_19 AC 28 ms
18,472 KB
testcase_20 AC 31 ms
18,632 KB
testcase_21 AC 26 ms
18,472 KB
testcase_22 AC 31 ms
18,520 KB
testcase_23 AC 30 ms
18,780 KB
testcase_24 AC 28 ms
18,524 KB
testcase_25 AC 29 ms
18,816 KB
testcase_26 AC 32 ms
18,804 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 1 "Main.cpp"
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <atcoder/modint>
#line 3 "nachia\\math\\combination.hpp"

namespace nachia{

template<class Modint>
class Comb{
private:
    std::vector<Modint> F;
    std::vector<Modint> iF;
public:
    void extend(int newN){
        int prevN = (int)F.size() - 1;
        if(prevN >= newN) return;
        F.resize(newN+1);
        iF.resize(newN+1);
        for(int i=prevN+1; i<=newN; i++) F[i] = F[i-1] * Modint::raw(i);
        iF[newN] = F[newN].inv();
        for(int i=newN; i>prevN; i--) iF[i-1] = iF[i] * Modint::raw(i);
    }
    Comb(int n = 1){
        F.assign(2, Modint(1));
        iF.assign(2, Modint(1));
        extend(n);
    }
    Modint factorial(int n) const { return F[n]; }
    Modint invFactorial(int n) const { return iF[n]; }
    Modint invOf(int n) const { return iF[n] * F[n-1]; }
    Modint comb(int n, int r) const {
        if(n < 0 || n < r || r < 0) return Modint(0);
        return F[n] * iF[r] * iF[n-r];
    }
    Modint invComb(int n, int r) const {
        if(n < 0 || n < r || r < 0) return Modint(0);
        return iF[n] * F[r] * F[n-r];
    }
    Modint perm(int n, int r) const {
        if(n < 0 || n < r || r < 0) return Modint(0);
        return F[n] * iF[n-r];
    }
    Modint invPerm(int n, int r) const {
        if(n < 0 || n < r || r < 0) return Modint(0);
        return iF[n] * F[n-r];
    }
    Modint operator()(int n, int r) const { return comb(n,r); }
};

} // namespace nachia
#line 8 "Main.cpp"


using namespace std;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
const i64 INF = 1001001001001001001;

using Modint = atcoder::static_modint<998244353>;


nachia::Comb<Modint> comb(2000000);


Modint hook(string s){
    vector<int> A, B;
    int a = 0, b = 0;
    for(char c : s) if(c == '0') a++;
    for(char c : s){
        if(c == '0'){ B.push_back(b); a--; }
        if(c == '1'){ A.push_back(a); b++; }
    }
    reverse(B.begin(), B.end());
    int lambda = 0;
    for(int a : A) lambda += a;
    Modint ans = 1;
    for(int i=1; i<=lambda; i++) ans *= i;
    rep(i,A.size()) rep(j,B.size()){
        if(A[i] <= j || B[j] <= i) continue;
        ans *= comb.invOf(A[i] + B[j] - i - j - 1);
    }
    return ans;
}


int opcount(string s){
    int ans = 0;
    rep(i,s.size()) rep(j,i) if(s[i] == '0' && s[j] == '1') ans++;
    return ans;
}


int main(){
    int N; cin >> N;
    vector<int> A(N+1); rep(i,N) cin >> A[i+1];
    string S;
    rep(i,N){
        rep(j,A[i+1]-A[i]) S.push_back('1');
        S.push_back('0');
    }

    string S2[2];
    rep(i,S.size()) S2[i%2].push_back(S[i]);
    Modint ans = hook(S2[0]) * hook(S2[1]);
    ans *= comb.comb(opcount(S2[0]) + opcount(S2[1]), opcount(S2[0]));

    rep(t,2) sort(S2[t].begin(), S2[t].end());

    string S3;
    rep(i,S.size()) S3.push_back(S2[i%2][i/2]);

    if(S3.find("10") != string::npos) ans = 0;
    cout << ans.val() << '\n';
    return 0;
}


struct ios_do_not_sync{
    ios_do_not_sync(){
        std::ios::sync_with_stdio(false);
        std::cin.tie(nullptr);
    }
} ios_do_not_sync_instance;


0