結果

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define ALL(v) v.begin(),v.end()
#define dbg(x) cerr << #x << ": " << (x) << endl;
template<class F, class S>
ostream& operator<<(ostream& os, pair<F,S>& p) {
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template<class Iter>
void print(Iter beg, Iter end) {
    for (Iter itr = beg; itr != end; ++itr) {
        cerr << *itr << ' ';
    }
    cerr << '\n';
}
ll x,k;
ll mod = 998244353;
ll modpow(ll x, ll n, ll mod) {
    x %= mod;
    ll res = 1;
    while (n > 0) {
        if (n&1) res = res*x%mod;
        x = x*x%mod;
        n >>= 1;
    }
    return res;
}
int main() {
    cin >> x >> k;
    if (x > 100 || k > 10) return 0;
    x = x * modpow(100, mod-2, mod) % mod;

    k *= 2;
    ll ans = 0;
    for (int mask = 0; mask < 1<<k; ++mask) {
        ll p = 1;
        int ma = 0;
        int now = 0;
        bool ok = true;
        for (int i = 0; i < k; ++i) {
            if (mask >> i & 1) {
                ++now;
                p = p * x % mod;
            } else {
                --now;
                p = p * ((1-x + mod) % mod) % mod;
            }
            if (now < 0) {
                ok = false;
                break;
            }
            ma = max(ma, now);
        }
        ok = (ok && (now == 0));
        if (ok) {
            ans += p * ma % mod;
            ans %= mod;
        }
    }
    cout << ans << '\n';
}
0