提出 #75449087


ソースコード 拡げる

#include <bits/stdc++.h>
using namespace std;
int main() {
    string S;
    cin >> S;
    int64_t XX = S.size();
    int64_t ans = 0;
    vector<int64_t> A(XX);
    vector<int64_t> B(XX);
    vector<int64_t> C(XX);
    if (S.at(0) == 'a') {
      A.at(0) = 1;
      B.at(0) = 0;
      C.at(0) = 0;
    }
    if (S.at(0) == 'b') {
      A.at(0) = 0;
      B.at(0) = 1;
      C.at(0) = 0;
    }
    if (S.at(0) == 'c') {
      A.at(0) = 0;
      B.at(0) = 0;
      C.at(0) = 1;
    }
    for (int i = 1; i < XX; i++) {
      if (S.at(i) == 'a') {
        A.at(i) = (A.at(i-1) + B.at(i-1) + C.at(i-1) + 1) % 998244353;
        B.at(i) = B.at(i-1);
        C.at(i) = C.at(i-1);
      }
      if (S.at(i) == 'b') {
        A.at(i) = A.at(i-1);
        B.at(i) = (A.at(i-1) + B.at(i-1) + C.at(i-1) + 1) % 998244353;
        C.at(i) = C.at(i-1);
      }
      if (S.at(i) == 'c') {
        A.at(i) = A.at(i-1);
        B.at(i) = B.at(i-1);
        C.at(i) = (A.at(i-1) + B.at(i-1) + C.at(i-1) + 1) % 998244353;
      }
    }
    ans = (A.at(XX-1) + B.at(XX-1) + C.at(XX-1)) % 998244353;
    cout << ans << endl;
    return 0;
  }

提出情報

提出日時
問題 D - Not Adjacent 2
ユーザ KOJIKEE
言語 C++23 (GCC 15.2.0)
得点 400
コード長 1168 Byte
結果 AC
実行時間 11 ms
メモリ 10796 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 3384 KiB
random_01.txt AC 11 ms 10608 KiB
random_02.txt AC 8 ms 9044 KiB
random_03.txt AC 10 ms 10580 KiB
random_04.txt AC 5 ms 6136 KiB
random_05.txt AC 10 ms 10716 KiB
random_06.txt AC 4 ms 5976 KiB
random_07.txt AC 11 ms 10632 KiB
random_08.txt AC 4 ms 5752 KiB
random_09.txt AC 10 ms 10636 KiB
random_10.txt AC 9 ms 9056 KiB
random_11.txt AC 11 ms 10696 KiB
random_12.txt AC 2 ms 3852 KiB
random_13.txt AC 11 ms 10632 KiB
random_14.txt AC 8 ms 8652 KiB
random_15.txt AC 11 ms 10664 KiB
random_16.txt AC 4 ms 5916 KiB
random_17.txt AC 10 ms 10576 KiB
random_18.txt AC 7 ms 8152 KiB
random_19.txt AC 10 ms 10668 KiB
random_20.txt AC 3 ms 4916 KiB
random_21.txt AC 10 ms 10696 KiB
random_22.txt AC 6 ms 7820 KiB
random_23.txt AC 9 ms 10692 KiB
random_24.txt AC 2 ms 4404 KiB
random_25.txt AC 9 ms 10796 KiB
sample_01.txt AC 1 ms 3288 KiB
sample_02.txt AC 1 ms 3432 KiB