結果

問題 No.1766 Tatsujin Remix
ユーザー rogi52rogi52
提出日時 2021-11-27 00:40:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 21 ms / 2,000 ms
コード長 2,905 bytes
コンパイル時間 1,901 ms
コンパイル使用メモリ 172,036 KB
実行使用メモリ 14,380 KB
最終ジャッジ日時 2023-09-12 06:12:34
合計ジャッジ時間 3,413 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 3 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 14 ms
9,388 KB
testcase_10 AC 14 ms
9,396 KB
testcase_11 AC 13 ms
9,548 KB
testcase_12 AC 14 ms
9,656 KB
testcase_13 AC 15 ms
11,080 KB
testcase_14 AC 20 ms
14,380 KB
testcase_15 AC 20 ms
14,240 KB
testcase_16 AC 20 ms
14,116 KB
testcase_17 AC 21 ms
14,196 KB
testcase_18 AC 21 ms
14,192 KB
testcase_19 AC 21 ms
14,132 KB
testcase_20 AC 21 ms
14,224 KB
testcase_21 AC 20 ms
14,188 KB
testcase_22 AC 20 ms
14,248 KB
testcase_23 AC 21 ms
14,272 KB
testcase_24 AC 19 ms
14,196 KB
testcase_25 AC 19 ms
14,104 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

template <int64_t Modulus>
struct Modint {
    using mint = Modint;
    long long v;
    Modint() : v(0) {}
    Modint(long long x) {
        x %= Modulus;
        if (x < 0) x += Modulus;
        v = x;
    }
    const long long& val() const { return v; }
    // 代入演算子
    mint& operator+=(const mint rhs) {
        v += rhs.v;
        if (v >= Modulus) v -= Modulus;
        return *this;
    }
    mint& operator-=(const mint rhs) {
        if (v < rhs.v) v += Modulus;
        v -= rhs.v;
        return *this;
    }
    mint& operator*=(const mint rhs) {
        v = v * rhs.v % Modulus;
        return *this;
    }
    mint& operator/=(mint rhs) { return *this = *this * rhs.inv(); }
    // 累乗, 逆元
    mint pow(long long n) const {
        mint x = *this, res = 1;
        while (n) {
            if (n & 1) res *= x;
            x *= x;
            n >>= 1;
        }
        return res;
    }
    mint inv() const { return pow(Modulus - 2); }
    // 算術演算子
    mint operator+(const mint rhs) const { return mint(*this) += rhs; }
    mint operator-(const mint rhs) const { return mint(*this) -= rhs; }
    mint operator*(const mint rhs) const { return mint(*this) *= rhs; }
    mint operator/(const mint rhs) const { return mint(*this) /= rhs; }
    mint operator-() const { return mint() - *this; }  // 単項
    // 入出力ストリーム
    friend ostream& operator<<(ostream& os, const mint& p) { return os << p.v; }
    friend istream& operator>>(istream& is, mint& p) {
        long long t;
        is >> t;
        p = mint(t);
        return (is);
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int n; cin >> n;
    string s = "";
    rep(i,n) {
        string t; cin >> t;
        s += t;
    }

    n *= 16;
    s += '.';
    auto f = [&](char c) {
        if(c == '.') return 0;
        if(c == 'd') return 1;
        return 2;
    };

    using mint = Modint<998244353>;
    vector<vector<mint>> dp(n + 1, vector<mint>(3, 0));
    dp[0][0] = 1;
    rep(i,n) {
        if(s[i] == '.') {
            dp[i + 1][f('.')] += dp[i][f('.')];
            if(i % 2 == 1) dp[i + 1][f('.')] += dp[i][f('d')] + dp[i][f('k')];

            if(s[i + 1] != 'd') {
                if(i % 2 == 0) dp[i + 1][f('d')] += dp[i][f('.')];
                dp[i + 1][f('d')] += dp[i][f('d')] + dp[i][f('k')];
            }

            if(s[i + 1] != 'k') {
                if(i % 2 == 0) dp[i + 1][f('k')] += dp[i][f('.')];
                dp[i + 1][f('k')] += dp[i][f('d')] + dp[i][f('k')];
            }
        } else {
            if(i % 2 == 0) dp[i + 1][f(s[i])] += dp[i][f('.')];
            dp[i + 1][f(s[i])] += dp[i][f('d')] + dp[i][f('k')];
        }
    }

    cout << dp[n][f('.')] + dp[n][f('d')] + dp[n][f('k')] << endl;
}
0