結果

問題 No.2872 Depth of the Parentheses
ユーザー InTheBloomInTheBloom
提出日時 2024-09-06 22:01:59
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 969 bytes
コンパイル時間 1,032 ms
コンパイル使用メモリ 90,820 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-06 22:02:09
合計ジャッジ時間 1,908 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20 WA * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

#include <atcoder/modint>

using namespace std;
using mint = atcoder::static_modint<998244353>;

int main () {
    int x, K; cin >> x >> K;

    // とんでもない高難易度問題かとおもったけど、シミュレーションが回る制約だった...

    if (10 < K) return 0;

    mint ans = 0;
    mint p = (mint(x) / 100).pow(K) * (1 - mint(x) / 100).pow(K);

    for (int S = 0; S < (1 << (2 * K)); S++) {
        int max_depth = [&] () {
            int res = 0;
            int cur = 0;
            for (int i = 0; i < 2 * K; i++) {
                int v = 1;
                if (0 < (S & (1 << i))) v = -1;
                cur += v;
                if (cur < 0) return -1;
                res = max(res, cur);
            }
            if (cur != 0) return -1;

            return res;
        }();

        if (max_depth == -1) continue;

        ans += p * max_depth;
    }

    cout << ans.val() << "\n";
}
0