提出 #75533478


ソースコード 拡げる

#include <bits/stdc++.h>
#define fastio cin.tie(0)->sync_with_stdio(0)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define compress(v) sort(all(v)), v.erase(unique(all(v)), v.end())
#define sz(x) (int)(x).size()
using namespace std;
typedef long long ll;

const int MOD = 998244353;
int main() {
    fastio; string s; cin >> s;
    vector<vector<ll>> dp(sz(s), vector<ll>(3));
    dp[0][s[0]-'a'] = 1;
    for (int i = 1; i < sz(s); i++) {
        dp[i][s[i]-'a']++;
        for (int j = 0; j < 3; j++) {
            dp[i][j] = (dp[i][j] + dp[i-1][j]) % MOD;
            if (j != s[i]-'a') dp[i][s[i]-'a'] = (dp[i][s[i]-'a'] + dp[i-1][j]) % MOD;
        }
    }
    cout << (dp[sz(s)-1][0] + dp[sz(s)-1][1] + dp[sz(s)-1][2]) % MOD << "\n";
    return 0;
}

提出情報

提出日時
問題 D - Not Adjacent 2
ユーザ Lov34ever
言語 C++23 (GCC 15.2.0)
得点 400
コード長 811 Byte
結果 AC
実行時間 18 ms
メモリ 20164 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 400 / 400
結果
AC × 2
AC × 28
セット名 テストケース
Sample sample_01.txt, sample_02.txt
All min.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, sample_01.txt, sample_02.txt
ケース名 結果 実行時間 メモリ
min.txt AC 1 ms 3488 KiB
random_01.txt AC 17 ms 20040 KiB
random_02.txt AC 12 ms 15896 KiB
random_03.txt AC 16 ms 20072 KiB
random_04.txt AC 7 ms 9696 KiB
random_05.txt AC 16 ms 20028 KiB
random_06.txt AC 7 ms 9320 KiB
random_07.txt AC 17 ms 20112 KiB
random_08.txt AC 7 ms 8928 KiB
random_09.txt AC 17 ms 20080 KiB
random_10.txt AC 13 ms 16488 KiB
random_11.txt AC 16 ms 20092 KiB
random_12.txt AC 2 ms 4584 KiB
random_13.txt AC 17 ms 20076 KiB
random_14.txt AC 13 ms 15764 KiB
random_15.txt AC 16 ms 20032 KiB
random_16.txt AC 7 ms 9184 KiB
random_17.txt AC 17 ms 20164 KiB
random_18.txt AC 11 ms 14304 KiB
random_19.txt AC 16 ms 20076 KiB
random_20.txt AC 5 ms 7144 KiB
random_21.txt AC 17 ms 20096 KiB
random_22.txt AC 11 ms 13992 KiB
random_23.txt AC 17 ms 19988 KiB
random_24.txt AC 4 ms 6164 KiB
random_25.txt AC 18 ms 19964 KiB
sample_01.txt AC 1 ms 3576 KiB
sample_02.txt AC 1 ms 3584 KiB