Submission #58124847


Source Code Expand

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

#define rep(i, x) for (int i = 0; i < (x); i++)

int main()
{
  int N, Q;
  string S;
  cin >> N >> Q >> S;
  int ans = 0;
  for (int i = 0; i < (int)S.size() - 2; i++)
  {
    if (S.substr(i, 3) == "ABC")
    {
      ++ans;
    }
  }

  for (int i = 0; i < Q; i++)
  {
    int X;
    char C;
    cin >> X >> C;
    --X;
    // 減少分
    if (2 <= X && S.substr(X - 2, 3) == "ABC")
    {
      --ans;
    }
    if (1 <= X && S.substr(X - 1, 3) == "ABC")
    {
      --ans;
    }
    if (S.substr(X, 3) == "ABC")
    {
      --ans;
    }

    S[X] = C;

    // 増加分
    if (2 <= X && S.substr(X - 2, 3) == "ABC")
    {
      ++ans;
    }
    if (1 <= X && S.substr(X - 1, 3) == "ABC")
    {
      ++ans;
    }
    if (S.substr(X, 3) == "ABC")
    {
      ++ans;
    }
    cout << ans << endl;
  }

  return 0;
}

Submission Info

Submission Time
Task C - Count ABC Again
User ryoh1004
Language C++ 23 (gcc 12.2)
Score 350
Code Size 887 Byte
Status AC
Exec Time 255 ms
Memory 3792 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 350 / 350
Status
AC × 3
AC × 17
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_handmade_00.txt, 01_handmade_01.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 02_random_11.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3512 KiB
00_sample_01.txt AC 1 ms 3624 KiB
00_sample_02.txt AC 1 ms 3492 KiB
01_handmade_00.txt AC 1 ms 3556 KiB
01_handmade_01.txt AC 255 ms 3680 KiB
02_random_00.txt AC 252 ms 3708 KiB
02_random_01.txt AC 254 ms 3684 KiB
02_random_02.txt AC 253 ms 3616 KiB
02_random_03.txt AC 251 ms 3592 KiB
02_random_04.txt AC 252 ms 3620 KiB
02_random_05.txt AC 251 ms 3692 KiB
02_random_06.txt AC 31 ms 3792 KiB
02_random_07.txt AC 234 ms 3504 KiB
02_random_08.txt AC 234 ms 3468 KiB
02_random_09.txt AC 236 ms 3488 KiB
02_random_10.txt AC 236 ms 3492 KiB
02_random_11.txt AC 235 ms 3512 KiB