結果
問題 | No.2872 Depth of the Parentheses |
ユーザー |
![]() |
提出日時 | 2024-09-07 14:49:35 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1 ms / 2,000 ms |
コード長 | 2,070 bytes |
コンパイル時間 | 555 ms |
コンパイル使用メモリ | 43,392 KB |
最終ジャッジ日時 | 2025-02-24 05:08:42 |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 20 RE * 5 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:66:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 66 | scanf("%d%d", &x, &k); | ~~~~~^~~~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*-** 2872.cc: No.2872 Depth of the Parentheses - yukicoder*/#include<cstdio>#include<algorithm>using namespace std;/* constant */const int MAX_K = 10;const int MAX_K2 = MAX_K * 2;const int MOD = 998244353;/* typedef */template<const int MOD>struct MI {int v;MI(): v() {}MI(int _v): v(_v % MOD) { if (v < 0) v += MOD; }MI(long long _v): v(_v % MOD) { if (v < 0) v += MOD; }explicit operator int() const { return v; }MI operator+(const MI m) const { return MI(v + m.v); }MI operator-(const MI m) const { return MI(v + MOD - m.v); }MI operator*(const MI m) const { return MI((long long)v * m.v); }MI &operator+=(const MI m) { return (*this = *this + m); }MI &operator-=(const MI m) { return (*this = *this - m); }MI &operator*=(const MI m) { return (*this = *this * m); }bool operator==(const MI m) const { return v == m.v; }bool operator!=(const MI m) const { return v != m.v; }MI pow(int n) const { // a^n % MODMI pm = 1, a = *this;while (n > 0) {if (n & 1) pm *= a;a *= a;n >>= 1;}return pm;}MI inv() const { return pow(MOD - 2); }MI operator/(const MI m) const { return *this * m.inv(); }MI &operator/=(const MI m) { return (*this = *this / m); }};using mi = MI<MOD>;/* global variables */mi dp[MAX_K2 + 1][MAX_K + 1][MAX_K + 1];/* subroutines *//* main */int main() {int x, k;scanf("%d%d", &x, &k);int k2 = k * 2;mi p0 = mi(x) / 100, p1 = mi(1) - p0;dp[0][0][0] = 1;for (int i = 0; i < k2; i++) // current posfor (int j = 0; j <= k; j++) // current depthfor (int m = 0; m <= k; m++) // max depthif ((int)dp[i][j][m]) {if (j < k) { // put '(' in prob p0int m1 = max(j + 1, m);dp[i + 1][j + 1][m1] += dp[i][j][m] * p0;}if (j > 0) { // put ')' in prob p1int m1 = max(j, m);dp[i + 1][j - 1][m1] += dp[i][j][m] * p1;}}mi sum = 0;for (int m = 0; m <= k; m++) sum += dp[k2][0][m] * m;printf("%d\n", (int)sum);return 0;}