結果
問題 |
No.3043 括弧列の数え上げ
|
ユーザー |
![]() |
提出日時 | 2025-03-04 05:47:42 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 25 ms / 2,000 ms |
コード長 | 930 bytes |
コンパイル時間 | 3,226 ms |
コンパイル使用メモリ | 274,908 KB |
実行使用メモリ | 17,632 KB |
最終ジャッジ日時 | 2025-03-04 05:47:48 |
合計ジャッジ時間 | 4,927 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 45 |
ソースコード
#define rep(i,n) for(int i=0;i<(int)(n);i++) #define ALL(v) v.begin(),v.end() typedef long long ll; #include<bits/stdc++.h> using namespace std; template<class T>using V=vector<T>; template<class T>using VV=V<V<T>>;//B(n,V<int>(n)) const int MOD=998244353; ll A[1010][1010]; ll B[1010][1010]; int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); int n; cin>>n; if(n%2){ cout<<0<<endl; return 0; } A[0][0]=1,B[n/2][n/2]=1; rep(i,n/2+1) rep(j,n/2+1){ if(i>j) continue; if(i) A[i][j]=(A[i][j]+A[i-1][j])%MOD; if(j) A[i][j]=(A[i][j]+A[i][j-1])%MOD; } for(int i=n/2;i>=0;i--) for(int j=n/2;j>=0;j--){ if(i>j) continue; if(i<n/2) B[i][j]=(B[i][j]+B[i+1][j])%MOD; if(j<n/2) B[i][j]=(B[i][j]+B[i][j+1])%MOD; } ll ans=0; rep(i,n/2+1) rep(j,n/2+1){ if(j-i<2) continue; ans=(ans+A[i][j]*B[i+1][j]%MOD*(j-i-1)%MOD)%MOD; } cout<<ans<<endl; return 0; }