結果

問題 No.2222 Respawn
ユーザー stoqstoq
提出日時 2022-05-31 03:32:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 901 bytes
コンパイル時間 2,297 ms
コンパイル使用メモリ 205,612 KB
実行使用メモリ 6,076 KB
最終ジャッジ日時 2023-09-24 05:10:37
合計ジャッジ時間 5,605 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

// f(x) = a + bx
using linear = pair<mint, mint>;
linear operator+(linear f, linear g) {
  return {f.first + g.first, f.second + g.second};
}
linear operator+(linear f, mint a) { return {f.first + a, f.second}; }
linear operator*(linear f, mint a) { return {f.first * a, f.second * a}; }
// f(x) = 0
mint solve(linear f) { return -f.first / f.second; }

int main() {
  int n;
  string s;
  cin >> n >> s;
  vector<mint> E(n + 1);
  vector<linear> f(n + 1);
  f[n - 1] = {0, 0};
  f[n] = {0, 1};
  const mint inv3 = mint(3).inv();

  for (int i = n - 2; i >= 0; i--) {
    if (s[i] == '#') {
      f[i] = {0, 1};
      continue;
    }
    E[i] = solve((f[i + 1] + f[i + 2] + linear{0, -2}) * inv3 + 1);
    f[i] = (f[i + 1] + f[i + 2] + E[i]) * inv3 + 1;
  }
  cout << E[0].val() << "\n";
}
0