結果

問題 No.1766 Tatsujin Remix
ユーザー penguinshunyapenguinshunya
提出日時 2021-11-26 23:19:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 2,483 bytes
コンパイル時間 1,895 ms
コンパイル使用メモリ 202,512 KB
実行使用メモリ 10,832 KB
最終ジャッジ日時 2023-09-12 05:35:08
合計ジャッジ時間 3,413 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
10,484 KB
testcase_01 AC 5 ms
10,356 KB
testcase_02 AC 4 ms
10,360 KB
testcase_03 AC 4 ms
10,420 KB
testcase_04 AC 5 ms
10,448 KB
testcase_05 AC 4 ms
10,400 KB
testcase_06 AC 5 ms
10,568 KB
testcase_07 AC 5 ms
10,444 KB
testcase_08 AC 5 ms
10,484 KB
testcase_09 AC 14 ms
10,496 KB
testcase_10 AC 13 ms
10,544 KB
testcase_11 AC 13 ms
10,540 KB
testcase_12 AC 13 ms
10,560 KB
testcase_13 AC 15 ms
10,564 KB
testcase_14 AC 20 ms
10,832 KB
testcase_15 AC 19 ms
10,612 KB
testcase_16 AC 19 ms
10,512 KB
testcase_17 AC 20 ms
10,516 KB
testcase_18 AC 20 ms
10,504 KB
testcase_19 AC 20 ms
10,540 KB
testcase_20 AC 19 ms
10,608 KB
testcase_21 AC 20 ms
10,504 KB
testcase_22 AC 20 ms
10,616 KB
testcase_23 AC 21 ms
10,540 KB
testcase_24 AC 15 ms
10,488 KB
testcase_25 AC 24 ms
10,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

template <int mod>
struct ModInt {
  int x;
  ModInt(): x(0) {}
  ModInt(long long a) { x = a % mod; if (x < 0) x += mod; }
  ModInt &operator+=(ModInt that) { x = (x + that.x) % mod; return *this; }
  ModInt &operator-=(ModInt that) { x = (x + mod - that.x) % mod; return *this; }
  ModInt &operator*=(ModInt that) { x = (long long) x * that.x % mod; return *this; }
  ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
  ModInt inverse() {
    int a = x, b = mod, u = 1, v = 0;
    while (b) { int t = a / b; a -= t * b; u -= t * v; swap(a, b); swap(u, v); }
    return ModInt(u);
  }
  #define op(o, p) ModInt operator o(ModInt that) { return ModInt(*this) p that; }
    op(+, +=) op(-, -=) op(*, *=) op(/, /=)
  #undef op
  friend ostream& operator<<(ostream &os, ModInt m) { return os << m.x; }
};

using mint = ModInt<998244353>;

mint dp[200000][3][3];

int main() {
  int n;
  cin >> n;
  string s;
  for (int i = 0; i < n; i++) {
    string t;
    cin >> t;
    s += t;
  }
  auto f = [&](char c) {
    switch (c) {
      case '.': return 0;
      case 'd': return 1;
      case 'k': return 2;
    }
  };
  n *= 16;
  dp[0][0][0] = 1;
  for (int i = 0; i < n; i++) {
    bool isodd = i % 2 == 0;
    int ni = i + 1;
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < 3; k++) {
        if (s[i] == '.') {
          if (!isodd) {
            if (j == 0 && k == 0) {
              dp[ni][f('.')][j] += dp[i][j][k];
            } else if (j != 0) {
              dp[ni][f('.')][j] += dp[i][j][k];
            }
          } else {
            if (j == 0) {
              dp[ni][f('.')][j] += dp[i][j][k];
            }
          }
        }
        if (s[i] == 'd' || (s[i] == '.' && (i == n - 1 || s[i + 1] == '.' || s[i + 1] == 'k'))) {
          if (isodd) {
            dp[ni][f('d')][j] += dp[i][j][k];
          } else {
            if (j != 0) {
              dp[ni][f('d')][j] += dp[i][j][k];
            }
          }
        }
        if (s[i] == 'k' || (s[i] == '.' && (i == n - 1 || s[i + 1] == '.' || s[i + 1] == 'd'))) {
          if (isodd) {
            dp[ni][f('k')][j] += dp[i][j][k];
          } else {
            if (j != 0) {
              dp[ni][f('k')][j] += dp[i][j][k];
            }
          }
        }
      }
    }
  }
  mint ans = 0;
  for (int j = 0; j < 3; j++) {
    for (int k = 0; k < 3; k++) {
      ans += dp[n][j][k];
    }
  }
  cout << ans << endl;
  return 0;
}
0