結果
| 問題 |
No.2872 Depth of the Parentheses
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-09-06 22:47:23 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 214 ms / 2,000 ms |
| コード長 | 1,110 bytes |
| コンパイル時間 | 5,069 ms |
| コンパイル使用メモリ | 310,304 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-09-06 22:47:43 |
| 合計ジャッジ時間 | 6,691 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 WA * 4 |
ソースコード
#include <bits/stdc++.h>
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using mint = modint998244353;
int main() {
int x, k;
cin >> x >> k;
k *= 2;
int k2 = 1<<k;
if (x == 0 or x == 100) {
puts("0");
return 0;
}
mint ans;
rep(s, k2) {
string t;
rep(i, k) {
if (s>>i&1) t += '(';
else t += ')';
}
bool ok = true;
int cnt = 0;
for (char c : t) {
cnt += c == '(' ? 1 : -1;
if (cnt < 0) {
ok = false;
break;
}
}
ok &= cnt == 0;
if (!ok) continue;
int mx = 0;
int now = 0;
for (char c : t) {
if (c == '(') now++, mx = max(mx, now);
else now--;
}
ans += mx;
}
ans *= mint(x).pow(k/2)*mint(100-x).pow(k/2);
ans /= mint(100).pow(k);
cout << ans.val() << '\n';
return 0;
}