結果

問題 No.3099 Parentheses Decomposition
ユーザー otoshigo
提出日時 2025-04-11 21:27:49
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 16 ms / 2,000 ms
コード長 1,146 bytes
コンパイル時間 1,880 ms
コンパイル使用メモリ 196,496 KB
実行使用メモリ 9,768 KB
最終ジャッジ日時 2025-04-11 21:27:54
合計ジャッジ時間 3,189 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}
template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}

#include<atcoder/modint>
using mint=atcoder::modint998244353;

const int MAX=500'500;
const int MOD=998244353;
mint fac[MAX+1],finv[MAX+1],inv[MAX+1];

void set_fac(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for (int i=2;i<=MAX;i++){
        fac[i]=fac[i-1]*i;
        inv[i]=-inv[MOD%i]*(MOD/i);
        finv[i]=finv[i-1]*inv[i];
    }
}

mint cmb(int n,int r){
    if (r<0||n<r)return 0;
    return fac[n]*finv[r]*finv[n-r];
}

void Solve(){
    int N;
    string S;
    cin>>N>>S;
    if(S[0]=='('&&S[1]=='('){
        mint ans=0;
        for(int i=0;i<=N/2;i++)ans+=cmb(N/2,i)*cmb(N/2,i);
        cout<<ans.val()<<"\n";
    }else{
        mint ans=mint(2).pow(N/2);
        cout<<ans.val()<<"\n";
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    set_fac();
    Solve();
}
0