alexjercan/bugnet huggingface dataset:
Problem p01811 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <queue>
#include <string>
using namespace std;
string S;
queue<string> Q;
int main() {
  cin >> S;
  Q.push(S);
  bool flag = false;
  if (S == "ABC") {
    flag = true;
    cout << "Yes" << endl;
    return 0;
  }
  while (!Q.empty()) {
    string T = Q.front();
    Q.pop();
    for (int i = 0; i < 3; i++) {
      string U = "";
      int D = T.size();
      bool OK = false;
      for (int j = 0; j < D; j++) {
        if (j < D - 2 && T.substr(j, 3) == "ABC") {
          U += (char)('A' + i);
          j += 2;
        } else {
          U += T[j];
          if (T[j] == (char)('A' + i)) {
            OK = true;
            break;
          }
        }
      }
      if (OK == true)
        continue;
      if (U == "ABC") {
        flag = true;
        break;
      }
      if (T != U)
        Q.push(U);
    }
    if (flag == true) {
      cout << "Yes" << endl;
      break;
    }
  }
  if (flag == false)
    cout << "No" << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <queue>
#include <string>
using namespace std;
string S;
queue<string> Q;
int main() {
  cin >> S;
  Q.push(S);
  bool flag = false;
  if (S == "ABC") {
    flag = true;
    cout << "Yes" << endl;
    return 0;
  }
  while (!Q.empty()) {
    string T = Q.front();
    Q.pop();
    for (int i = 0; i < 3; i++) {
      string U = "";
      int D = T.size();
      for (int j = 0; j < D; j++) {
        if (j < D - 2 && T[j] == 'A' && T[j + 1] == 'B' && T[j + 2] == 'C') {
          U += (char)('A' + i);
          j += 2;
        } else {
          U += T[j];
        }
      }
      if (U == "ABC") {
        flag = true;
        break;
      }
      if (T == U)
        Q.push(U);
    }
    if (flag == true) {
      cout << "Yes" << endl;
      break;
    }
  }
  if (flag == false)
    cout << "No" << endl;
  return 0;
}
Problem p01811 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

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

bool f(const string &s) {
  // cout<< s<< endl;
  if (s == "ABC")
    return true;
  if (s.size() <= 3)
    return false;
  int n = s.size();
  char c;
  if (s.substr(0, 3) == "ABC")
    c = 'A';
  else if (s.substr(n - 3, 3) == "ABC")
    c = 'C';
  else
    c = 'B';
  string t = "";
  rep(i, n) {
    if (s.substr(i, 3) == "ABC") {
      t += c;
      i += 2;
    } else {
      t += s[i];
    }
  }
  if (s.size() == t.size())
    return false;
  string u = "";
  int m = t.size();
  rep(i, m) {
    if (t[i] == c) {
      u += "ABC";
    } else {
      u += t[i];
    }
  }
  if (s == u)
    return f(t);
  else
    return false;
}

int main() {

  string s;
  cin >> s;

  bool ok = f(s);
  if (ok)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  // cout<< ret<< endl;

  return 0;
}


Error: MLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

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

bool f(const string &s) {
  // cout<< s<< endl;
  if (s == "ABC")
    return true;
  if (s.size() <= 3)
    return false;
  int n = s.size();
  char c;
  if (s.substr(0, 3) == "ABC")
    c = 'A';
  else if (s.substr(n - 3, 3) == "ABC")
    c = 'C';
  else
    c = 'B';
  string t = "";
  rep(i, n) {
    if (s.substr(i, 3) == "ABC") {
      t += c;
      i += 2;
    } else {
      t += s[i];
    }
  }
  string u = "";
  int m = t.size();
  rep(i, m) {
    if (t[i] == c) {
      u += "ABC";
    } else {
      u += t[i];
    }
  }
  if (s == u)
    return f(t);
  else
    return false;
}

int main() {

  string s;
  cin >> s;

  bool ok = f(s);
  if (ok)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  // cout<< ret<< endl;

  return 0;
}
Problem p01811 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define REP(i, n, N) for (int i = n; i < N; i++)
#define p(S) cout << (S) << endl
#define ck(a, b) (0 <= (a) && (a) < b)
using namespace std;

string abcgene(string anss) {
  queue<string> q;
  q.push(anss);
  string c[3] = {"A", "B", "C"};
  map<string, bool> m;
  m[anss] = true;
  while (!q.empty()) {
    string s = q.front();
    q.pop();
    if (s == "ABC")
      return "Yes";
    REP(j, 0, 3) {
      string tmps = s;
      int cnt = 0;
      REP(i, 0, (int)tmps.size() - 2) {
        if (tmps[i] == 'A' && tmps[i + 1] == 'B' && tmps[i + 2] == 'C') {
          tmps.replace(i, 3, c[j]);
          cnt++;
        }
      }
      if (cnt != count(tmps.begin(), tmps.end(), 'A' + j))
        continue;
      if (!m[tmps]) {
        m[tmps] = true;
        q.push(tmps);
      }
    }
  }
  return "No";
}

int main() {
  string ans;
  cin >> ans;
  p(abcgene(ans));
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define REP(i, n, N) for (int i = n; i < N; i++)
#define p(S) cout << (S) << endl
#define ck(a, b) (0 <= (a) && (a) < b)
using namespace std;

string abcgene(string anss) {
  queue<string> q;
  q.push(anss);
  string c[3] = {"A", "B", "C"};
  while (!q.empty()) {
    string s = q.front();
    q.pop();
    if (s == "ABC")
      return "Yes";
    REP(j, 0, 3) {
      string tmps = s;
      int cnt = 0;
      REP(i, 0, (int)tmps.size() - 2) {
        if (tmps[i] == 'A' && tmps[i + 1] == 'B' && tmps[i + 2] == 'C') {
          tmps.replace(i, 3, c[j]);
          cnt++;
        }
      }
      if (cnt != count(tmps.begin(), tmps.end(), 'A' + j))
        continue;
      if (tmps.size() >= 3)
        q.push(tmps);
    }
  }
  return "No";
}

int main() {
  string ans;
  cin >> ans;
  p(abcgene(ans));
  return 0;
}
Problem p01811 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define REP(i, n, N) for (int i = n; i < N; i++)
#define p(S) cout << (S) << endl
#define ck(a, b) (0 <= (a) && (a) < b)
using namespace std;

string abcgene(string anss) {
  queue<string> q;
  q.push(anss);
  string c[3] = {"A", "B", "C"};
  map<string, bool> m;
  m[anss] = true;
  while (!q.empty()) {
    string s = q.front();
    q.pop();
    if (s == "ABC")
      return "Yes";
    REP(j, 0, 3) {
      string tmps = s;
      int cnt = 0;
      REP(i, 0, (int)tmps.size() - 2) {
        if (tmps.substr(i, 3) == "ABC") {
          tmps.replace(i, 3, c[j]);
          cnt++;
        }
      }
      if (cnt != count(tmps.begin(), tmps.end(), 'A' + j))
        continue;
      if (!m[tmps]) {
        m[tmps] = true;
        q.push(tmps);
      }
    }
  }
  return "No";
}

int main() {
  string ans;
  cin >> ans;
  p(abcgene(ans));
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define REP(i, n, N) for (int i = n; i < N; i++)
#define p(S) cout << (S) << endl
#define ck(a, b) (0 <= (a) && (a) < b)
using namespace std;

string abcgene(string anss) {
  queue<string> q;
  q.push(anss);
  string c[3] = {"A", "B", "C"};
  map<string, bool> m;
  m[anss] = true;
  while (!q.empty()) {
    string s = q.front();
    q.pop();
    if (s == "ABC")
      return "Yes";
    REP(j, 0, 3) {
      string tmps = s;
      int cnt = 0;
      REP(i, 0, (int)tmps.size() - 2) {
        if (tmps.substr(i, 3) == "ABC") {
          tmps.replace(i, 3, c[j]);
          cnt++;
        }
      }
      if (tmps[tmps.size() - 1] != 'C' || tmps[tmps.size() - 2] == 'A')
        continue;
      if (!m[tmps]) {
        m[tmps] = true;
        q.push(tmps);
      }
    }
  }
  return "No";
}

int main() {
  string ans;
  cin >> ans;
  p(abcgene(ans));
  return 0;
}
Problem p01811 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define REP(i, n, N) for (int i = n; i < N; i++)
#define p(S) cout << (S) << endl
using namespace std;

string abcgene(string anss) {
  string c;
  string s = anss;
  string tmp = "a";
  while (1) {
    if (s == "ABC")
      return "Yes";
    if (tmp == s || s.size() < 5)
      return "No";
    if (s.substr(0, 3) == "ABC")
      c = "A";
    else if (s.substr(s.size() - 3, 3) == "ABC")
      c = "C";
    else
      c = "B";
    tmp = s;
    int cnt = 0;
    REP(i, 0, (int)s.size() - 2) {
      if (s.substr(i, 3) == "ABC") {
        s.replace(i, 3, c);
        cnt++;
      }
    }
    if (cnt != count(s.begin(), s.end(), c[0]))
      return "No";
  }
}

int main() {
  string ans;
  cin >> ans;
  p(abcgene(ans));
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define REP(i, n, N) for (int i = n; i < N; i++)
#define p(S) cout << (S) << endl
#define ck(a, b) (0 <= (a) && (a) < b)
using namespace std;

string abcgene(string anss) {
  string c;
  string s = anss;
  string tmp;
  while (1) {
    if (s == "ABC")
      return "Yes";
    if (!s.find("ABC") || tmp == s)
      return "No";
    if (s.substr(0, 3) == "ABC")
      c = "A";
    else if (s.substr(s.size() - 3, 3) == "ABC")
      c = "C";
    else
      c = "B";
    tmp = s;
    REP(i, 0, (int)s.size() - 2) {
      if (s.substr(i, 3) == "ABC") {
        s.replace(i, 3, c);
      }
    }
  }
}

int main() {
  string ans;
  cin >> ans;
  p(abcgene(ans));
  return 0;
}
Problem p01811 (C++) — buggy submission, verdict: Time Limit Exceeded

/*
2017_05_04
????????°????????????????????????
?????????????????????????????????????????????????????????????????????
???find, erase ?????????
*/

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define CH(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)

using namespace std;

string S;
string x[] = {"A", "B", "C"};
char cx[] = {'A', 'B', 'C'};

int main() {
  cin >> S;
  while (1) {
    // cout<<"S: "<<S<<endl;
    if (S == "ABC") {
      cout << "Yes" << endl;
      return 0;
    }
    if (S.size() < 5)
      break;
    int i = 1;
    if (S.substr(0, 3) == "ABC")
      i = 0;
    else if (S.substr(S.size() - 3, 3) == "ABC")
      i = 2;
    int cnt = 0;
    REP(pos, 0, S.size() - 2) {
      if (S.substr(pos, 3) == "ABC") {
        S.replace(pos, 3, x[i]);
        cnt++;
      }
    }
    if (cnt == 0 || cnt != count(S.begin(), S.end(), cx[i]))
      break;
  }
  cout << "No" << endl;

  return 0;
}

Error: TLE

Fixed submission:

/*
2017_05_04
????????°????????????????????????
?????????????????????????????????????????????????????????????????????
???find, erase ?????????
*/

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define CH(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)

using namespace std;

string S, ss;
string x[] = {"A", "B", "C"};
char cx[] = {'A', 'B', 'C'};
bool ans = false;

int main() {
  cin >> ss;
  while (1) {
    if (ss == "ABC") {
      cout << "Yes" << endl;
      return 0;
    }
    if (ss.size() < 5)
      break;
    S = ss;
    bool flag = false;
    int i = 1;
    if (S.substr(0, 3) == "ABC")
      S.replace(0, 3, "A"), i = 0, flag = true;
    else if (S.substr(S.size() - 3, 3) == "ABC")
      S.replace(S.size() - 3, 3, "C"), i = 2, flag = true;
    string::size_type pos = S.find("ABC");
    while (pos != string::npos && S.size() != 3) {
      S.replace(pos, 3, x[i]);
      pos = S.find("ABC");
      flag = true;
    }
    /*?????\\??????ABC???AorC????????????????????£?????´???*/
    if (ss.size() != S.size() && i != 1)
      break;
    ss = S;
  }
  cout << "No" << endl;

  return 0;
}
Problem p01811 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>
using namespace std;

int main() {
  string s;
  cin >> s;
  if (s.length() < 3) {
    cout << "No" << endl;
    return 0;
  }
  while (s != "ABC") {
    string t = "";
    for (int i = 0; i < s.length() - 2; i++) {
      if (s.substr(i, 3) == "ABC") {
        for (int j = 0; j < 3; j++)
          s[i + j] = ' ';
      }
    }
    bool a = false, b = false, c = false;
    for (int i = 0; i < s.length(); i++) {
      if (s[i] == 'A')
        a = true;
      else if (s[i] == 'B')
        b = true;
      else if (s[i] == 'C')
        c = true;
    }
    char cha = ' ';
    if (a && b)
      cha = 'C';
    if (b && c)
      cha = 'A';
    if (c && a)
      cha = 'B';
    if (cha == ' ' || (a && b && c)) {
      cout << "No" << endl;
      return 0;
    }
    for (int i = 0; i < s.length(); i++) {
      if (s[i] == ' ') {
        t = t + cha;
        i += 2;
      } else
        t = t + s[i];
    }
    if (t == s) {
      cout << "No" << endl;
      return 0;
    }
    s = t;
  }
  cout << "Yes" << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <string>
using namespace std;

int main() {
  string s;
  cin >> s;
  while (s != "ABC") {
    string t = "";
    for (int i = 0; i < s.length() - 2; i++) {
      if (s.substr(i, 3) == "ABC") {
        for (int j = 0; j < 3; j++)
          s[i + j] = ' ';
      }
    }
    bool a = false, b = false, c = false;
    for (int i = 0; i < s.length(); i++) {
      if (s[i] == 'A')
        a = true;
      else if (s[i] == 'B')
        b = true;
      else if (s[i] == 'C')
        c = true;
    }
    char cha = ' ';
    if (a && b)
      cha = 'C';
    if (b && c)
      cha = 'A';
    if (c && a)
      cha = 'B';
    if (cha == ' ' || (a && b && c)) {
      cout << "No" << endl;
      return 0;
    }
    for (int i = 0; i < s.length(); i++) {
      if (s[i] == ' ') {
        t = t + cha;
        i += 2;
      } else
        t = t + s[i];
    }
    if (t == s) {
      cout << "No" << endl;
      return 0;
    }
    s = t;
  }
  cout << "Yes" << endl;
  return 0;
}
Problem p01811 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
using namespace std;
string str;
int main() {
  cin >> str;
  queue<string> que;
  que.push(str);
  bool ret = (str == "ABC");
  while (!ret && !que.empty()) {
    string s1 = que.front();
    que.pop();
    vector<int> v1(s1.size(), 0);
    for (int i = 2; i < s1.size(); i++) {
      if (s1[i - 2] == 'A' && s1[i - 1] == 'B' && s1[i] == 'C') {
        v1[i - 2] = v1[i - 1] = v1[i] = 1;
      }
    }
    vector<bool> ok1(3, true);
    for (int i = 0; i < s1.size(); i++) {
      if (v1[i] == 0)
        ok1[s1[i] - 65] = false;
    }
    for (int i = 0; i < 3; i++) {
      if (!ok1[i])
        continue;
      string res;
      for (int j = 0; j < s1.size();) {
        if (j <= s1.size() - 3 && v1[j] == 1)
          res += (char)(i + 65), j += 3;
        else
          res += s1[j], j++;
      }
      if (res == "ABC") {
        ret = true;
        break;
      }
      if (res.size() != s1.size())
        que.push(res);
    }
  }
  cout << (ret ? "Yes" : "No") << endl;
  return 0;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
using namespace std;
string str;
int main() {
  cin >> str;
  queue<string> que;
  que.push(str);
  bool ret = (str == "ABC");
  while (!ret && !que.empty()) {
    string s1 = que.front();
    que.pop();
    vector<int> v1(s1.size(), 0);
    for (int i = 2; i < s1.size(); i++) {
      if (s1[i - 2] == 'A' && s1[i - 1] == 'B' && s1[i] == 'C') {
        v1[i - 2] = v1[i - 1] = v1[i] = 1;
      }
    }
    vector<bool> ok1(3, true);
    for (int i = 0; i < s1.size(); i++) {
      if (v1[i] == 0)
        ok1[s1[i] - 65] = false;
    }
    for (int i = 0; i < 3; i++) {
      string res;
      for (int j = 0; j < s1.size();) {
        if (j <= s1.size() - 3 && v1[j] == 1)
          res += (char)(i + 65), j += 3;
        else
          res += s1[j], j++;
      }
      if (res == "ABC") {
        ret = true;
        break;
      }
      que.push(res);
    }
  }
  cout << (ret ? "Yes" : "No") << endl;
  return 0;
}
Problem p01811 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define REP(i, a, n) for (int i = a; i < n; i++)
#define RREP(i, a, n) for (int i = n - 1; i >= a; i--)
#define INF 100000000
#define ll long long

queue<string> str;
int main() {
  string S;
  vector<string> gene;
  cin >> S;

  gene.push_back("A");
  gene.push_back("B");
  gene.push_back("C");

  str.push(S);
  while (!str.empty()) {
    string s = str.front();
    str.pop();

    if (s.size() == 3 && s == "ABC") {
      cout << "Yes" << endl;
      return 0;
    }

    REP(i, 0, 3) {
      int cnt = 0;
      string ns = s;
      vector<int> idx;
      bool flag = false;

      RREP(j, 0, (int)s.size() - 2) {
        if (ns[j] == 'A' && ns[j + 1] == 'B' && ns[j + 2] == 'C') {
          flag = true;
          idx.push_back(j);
          cnt++;
        }
      }

      if (cnt != count(ns.begin(), ns.end(), 'A' + i))
        continue;

      REP(k, 0, (int)idx.size()) { ns.replace(idx[k], 3, gene[i]); }

      if (flag)
        str.push(ns);
    }
  }

  cout << "No" << endl;
  return 0;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define REP(i, a, n) for (int i = a; i < n; i++)
#define RREP(i, a, n) for (int i = n - 1; i >= a; i--)
#define INF 100000000
#define ll long long

queue<string> str;
int main() {
  string S;
  vector<string> gene;
  cin >> S;

  gene.push_back("A");
  gene.push_back("B");
  gene.push_back("C");

  str.push("ABC");
  while (!str.empty()) {
    string s = str.front();
    str.pop();

    if (s == S) {
      cout << "Yes" << endl;
      return 0;
    }

    REP(i, 0, 3) {
      int t = 0;
      string ns = s;
      vector<int> idx;
      while (1) {
        int next = s.find(gene[i], t);
        if (next == -1)
          break;
        idx.push_back(next);
        t = next + 1;
      }

      RREP(j, 0, idx.size()) { ns.replace(idx[j], 1, "ABC"); }

      if (ns.size() <= S.size()) {
        str.push(ns);
      }
    }
  }

  cout << "No" << endl;
  return 0;
}
Problem p01811 (C++) — buggy submission, verdict: Time Limit Exceeded


#include <bits/stdc++.h>

using namespace std;
char arr[3] = {'A', 'B', 'C'};

string conv(string s, int idx) {
  string res = "";
  int i = 0;
  for (; i < (int)s.length() - 2; i++) {
    string sub = s.substr(i, 3);
    if (sub == "ABC") {
      res += arr[idx];
      i += 2;
    } else
      res += s[i];
  }
  res += s.substr(i);
  return res;
}

string reconv(string s, int idx) {
  string res = "";
  for (int i = 0; i < (int)s.length(); i++) {
    if (s[i] == arr[idx])
      res += "ABC";
    else
      res += s[i];
  }
  return res;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  string s;
  cin >> s;
  if (s == "ABC") {
    cout << "Yes" << endl;
    return 0;
  }
  queue<string> que;
  que.push(s);
  while (!que.empty()) {
    string now = que.front();
    que.pop();
    for (int i = 0; i < 3; i++) {
      string tmp = conv(now, i);
      if (tmp == now)
        break;
      if (now != reconv(tmp, i))
        continue;
      if (tmp == "ABC") {
        cout << "Yes" << endl;
        return 0;
      }
      que.push(tmp);
    }
  }
  cout << "No" << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

string conv(string s, int idx) {
  string res = "";
  string arr[3] = {"A", "B", "C"};
  int i = 0;
  for (; i < (int)s.length() - 2; i++) {
    string sub = s.substr(i, 3);
    if (sub == "ABC") {
      res += arr[idx];
      i += 2;
    } else
      res += s[i];
  }
  res += s.substr(i);
  return res;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  string s;
  cin >> s;
  if (s == "ABC") {
    cout << "Yes" << endl;
    return 0;
  }
  queue<string> que;
  que.push(s);
  while (!que.empty()) {
    string now = que.front();
    que.pop();
    for (int i = 0; i < 3; i++) {
      string tmp = conv(now, i);
      // cout<<tmp<<endl;
      if (tmp == now)
        continue;
      if (tmp == "ABC") {
        cout << "Yes" << endl;
        return 0;
      }
      que.push(tmp);
    }
  }
  cout << "No" << endl;
  return 0;
}
Problem p01811 (C++) — buggy submission, verdict: Time Limit Exceeded

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, n) repl(i, 0, n)
#define each(itr, v) for (auto itr : v)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x "=" << x << endl
#define mmax(x, y) (x > y ? x : y)
#define mmin(x, y) (x < y ? x : y)
#define maxch(x, y) x = mmax(x, y)
#define minch(x, y) x = mmin(x, y)
#define uni(x) x.erase(unique(all(x)), x.end())
#define exist(x, y) (find(all(x), y) != x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX / 3

string ss[] = {"A", "B", "C"};

bool dfs(string s) {
  if (s == "ABC")
    return true;
  if (s.length() <= 3)
    return false;
  int n = s.length();

  bool used[3];
  bool ok = false;

  memset(used, 0, sizeof(used));
  for (int j = 0; j < n;) {
    if (s.substr(j, 3) == "ABC") {
      ok = true;
      j += 3;
    } else {
      used[s[j] - 'A'] = true;
      j++;
    }
  }
  if (!ok)
    return false;

  rep(i, 3) {
    if (used[i])
      continue;
    string ns;
    for (int j = 0; j < n;) {
      if (j < n - 2 && s.substr(j, 3) == "ABC") {
        ns += ss[i];
        j += 3;
      } else {
        ns += s[j];
        j++;
      }
    }
    if (dfs(ns)) {
      return true;
    }
  }
  return false;
}

int main() {
  cin.sync_with_stdio(false);
  string s;
  cin >> s;
  if (dfs(s))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, n) repl(i, 0, n)
#define each(itr, v) for (auto itr : v)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x "=" << x << endl
#define mmax(x, y) (x > y ? x : y)
#define mmin(x, y) (x < y ? x : y)
#define maxch(x, y) x = mmax(x, y)
#define minch(x, y) x = mmin(x, y)
#define uni(x) x.erase(unique(all(x)), x.end())
#define exist(x, y) (find(all(x), y) != x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX / 3

string ss[] = {"A", "B", "C"};

bool dfs(string s) {
  if (s == "ABC")
    return true;
  if (s.length() <= 3)
    return false;
  int n = s.length();
  rep(i, 3) {
    string ns;
    rep(j, n) {
      if (j < n - 2 && s.substr(j, 3) == "ABC") {
        ns += ss[i];
        j += 2;
      } else
        ns += s[j];
    }
    if (ns.length() < s.length() && dfs(ns)) {
      return true;
    }
  }
  return false;
}

int main() {
  cin.sync_with_stdio(false);
  string s;
  cin >> s;
  if (dfs(s))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}