結果
問題 | No.2872 Depth of the Parentheses |
ユーザー |
![]() |
提出日時 | 2024-09-06 22:00:17 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,120 bytes |
コンパイル時間 | 2,038 ms |
コンパイル使用メモリ | 194,180 KB |
最終ジャッジ日時 | 2025-02-24 04:20:37 |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 WA * 4 |
ソースコード
#include<bits/stdc++.h> using namespace std; #define pb emplace_back #define mp make_pair using ll = long long; using pii = pair<int,int>; constexpr int mod = 998244353; constexpr int inf = 0x3f3f3f3f; constexpr int N = 2e5 + 10; ll pow_mod(ll x, ll p){ ll s = 1; while(p){ if(p & 1) s = s * x % mod; x = x * x % mod; p >>= 1; } return s; } void add(int &x, int y){ x += y; if(x >= mod) x -= mod; } int dp[30][30][30]; void _main(){ int x, K; cin >> x >> K; if(K > 10){ cout << "0\n"; return; } ll p = pow_mod(100, mod - 2) * x % mod; ll q = (1 + mod - p) % mod; dp[0][0][0] = 1; K <<= 1; for(int i=0; i<K; ++i){ for(int j=0; j<=i; ++j){ for(int k=0; k<=j; ++k){ add(dp[i+1][max(j, k + 1)][k + 1], 1ll * dp[i][j][k] * p % mod); if(k){ add(dp[i+1][j][k - 1], 1ll * dp[i][j][k] * q % mod); } } } } ll ans = 0; for(int i=1; i<=K; ++i){ ans += 1ll * dp[K][i][0] * i % mod; } cout << ans % mod << '\n'; } int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); _main(); return 0; }