Submission #75446772


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define LONGMAX 1e18
#define INTMAX 2147483647

int main(void)
{
    ll MOD = 998244353;
    string S;
    cin >> S;
    vector<ll> dp(3, 0); // a:0, b:1, c:2
    // 最後がaで終わる部分列の数がdp[0]
    // S[i]がaだったら、dp[a] = 1 + dp[b] + dp[c]
    // その文字自体と、そのときのdp[ほかのやつ]を加えるといい
    // この1をdp[a]にすると連続部分列を含むことになる
    for (ll i = 0, n = S.length(); i < n; i++)
    {
        if (S[i] == 'a')
        {
            dp[0] += (1 + dp[1] + dp[2]) % MOD;
            dp[0] %= MOD;
        }
        else if (S[i] == 'b')
        {
            dp[1] += (1 + dp[0] + dp[2]) % MOD;
            dp[1] %= MOD;
        }
        else
        {
            dp[2] += (1 + dp[0] + dp[1]) % MOD;
            dp[2] %= MOD;
        }
    }
    cout << (dp[0] + dp[1] + dp[2]) % MOD << endl;
    return 0;
}

Submission Info

Submission Time
Task D - Not Adjacent 2
User lalashvbp
Language C++23 (GCC 15.2.0)
Score 400
Code Size 1009 Byte
Status AC
Exec Time 7 ms
Memory 4016 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 2
AC × 28
Set Name Test Cases
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
Case Name Status Exec Time Memory
min.txt AC 1 ms 3464 KiB
random_01.txt AC 7 ms 3896 KiB
random_02.txt AC 5 ms 3712 KiB
random_03.txt AC 7 ms 3884 KiB
random_04.txt AC 3 ms 3860 KiB
random_05.txt AC 7 ms 4016 KiB
random_06.txt AC 3 ms 3652 KiB
random_07.txt AC 7 ms 3896 KiB
random_08.txt AC 3 ms 3896 KiB
random_09.txt AC 7 ms 3836 KiB
random_10.txt AC 6 ms 3704 KiB
random_11.txt AC 7 ms 3896 KiB
random_12.txt AC 2 ms 3524 KiB
random_13.txt AC 7 ms 3952 KiB
random_14.txt AC 5 ms 3844 KiB
random_15.txt AC 6 ms 3824 KiB
random_16.txt AC 3 ms 3664 KiB
random_17.txt AC 6 ms 3940 KiB
random_18.txt AC 4 ms 3696 KiB
random_19.txt AC 6 ms 3956 KiB
random_20.txt AC 2 ms 3768 KiB
random_21.txt AC 6 ms 3948 KiB
random_22.txt AC 4 ms 3824 KiB
random_23.txt AC 6 ms 3812 KiB
random_24.txt AC 2 ms 3588 KiB
random_25.txt AC 6 ms 3824 KiB
sample_01.txt AC 1 ms 3452 KiB
sample_02.txt AC 1 ms 3620 KiB