結果

問題 No.2872 Depth of the Parentheses
ユーザー tama04
提出日時 2024-09-22 19:43:36
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 78 ms / 2,000 ms
コード長 697 bytes
コンパイル時間 3,577 ms
コンパイル使用メモリ 277,108 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-22 19:43:50
合計ジャッジ時間 4,928 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/modint>
using namespace std;
using namespace atcoder;

using mint = modint998244353;

int main(void) {
	int ix, k;
	cin >> ix >> k;

	int k2 = k * 2;

	mint x = ix;
	mint ans = 0;
	int depth = -1, cur = -1;
	for (int bit = 0; bit < (1 << k2); bit++) {
		depth = 0;
		cur = 0;

		bool flag = true;
		for (int i = 0; i < k2; i++) {
			if (bit & (1 << i)) {
				cur++;
				depth = max(depth, cur);
			}
			else {
				cur--;
				if (cur < 0) flag = false;
			}
		}

		if (cur == 0 && flag) {
			ans += (mint)depth;
		}
	}

	ans *= (x.pow(k) * ((mint)100 - x).pow(k));
	for (int i = 0; i < k2; i++) ans /= (mint)100;

	cout << ans.val() << endl;

	return 0;
}
0