Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 6):
#include <bits/stdc++.h>
#define ll long long
using namespace std;

vector<bool> digitchanges(9);
 //track the digits already searched

bool searchchanges(int curmod9, int remaining2s, int remaining3s){
    if(curmod9 == 0){
        return true;
    }
    // 1 2 3 4 5 6 7 8 0
    /*
    if(digitchanges[curmod9] == true){
        cout << curmod9 << "\n";
        return false;
    }
    */
    if(remaining2s == 0 && remaining3s == 0){
       // cout << remaining2s << " " << remaining3s << "\n";
        return false;
    }
    digitchanges[curmod9] = true;
    bool true2 = false;
    bool true3 = false;
    if(remaining2s > 0){
        int newmod9 = (2 + curmod9) % 9;
        true2 = searchchanges(newmod9, remaining2s-1, remaining3s);
    }
    if(remaining3s > 0){
        int newmod9 = (6+curmod9) % 9;
        true3 = searchchanges(newmod9, remaining2s, remaining3s-1);
    }
    if(true2 == true || true3 == true){
        return true;
    }
    return false;
}

void solve() {
    int n[2]; //only store twos and threes
    n[0] = 0; //count of 2s
    n[1] = 0; //count of 3s
    int totalmod9 = 0;
    string s;
    cin >> s;
    int len = s.length();
    for(int i = 0; i < len; i++){
        if(s[i] == '3'){
            n[1]++;
        }
        if(s[i] == '2'){
            n[0]++;
        }
        int digit = s[i] - '0';
        totalmod9 += digit;
        totalmod9 = totalmod9 % 9;
    }
    
    if(n[0] > 10){
        cout << "YES";
    } else if(n[0]>5&&n[1]>5){
        cout << "YES";
    } else if(n[1]>5 && totalmod9%3==0){
        cout << "YES";
    }else if(searchchanges(totalmod9, n[0], n[1]) == true){
        cout << "YES";
    } else{
        cout << "NO";
    }
    return;
}

int main() {
    int TESTS; cin >> TESTS;
    while (TESTS --> 0) {
        solve();
        cout << '\n';
    }
    return 0;
}

Submission (verdict: Time limit exceeded on test 6):
#include <bits/stdc++.h>
#define ll long long
using namespace std;

vector<bool> digitchanges(9);
 //track the digits already searched

bool searchchanges(int curmod9, int remaining2s, int remaining3s){
    if(curmod9 == 0){
        return true;
    }
    // 1 2 3 4 5 6 7 8 0
    /*
    if(digitchanges[curmod9] == true){
        cout << curmod9 << "\n";
        return false;
    }
    */
    if(remaining2s == 0 && remaining3s == 0){
       // cout << remaining2s << " " << remaining3s << "\n";
        return false;
    }
    digitchanges[curmod9] = true;
    bool true2 = false;
    bool true3 = false;
    if(remaining2s > 0){
        int newmod9 = (2 + curmod9) % 9;
        true2 = searchchanges(newmod9, remaining2s-1, remaining3s);
    }
    if(remaining3s > 0){
        int newmod9 = (6+curmod9) % 9;
        true3 = searchchanges(newmod9, remaining2s, remaining3s-1);
    }
    if(true2 == true || true3 == true){
        return true;
    }
    return false;
}

void solve() {
    int n[2]; //only store twos and threes
    n[0] = 0; //count of 2s
    n[1] = 0; //count of 3s
    int totalmod9 = 0;
    string s;
    cin >> s;
    int len = s.length();
    for(int i = 0; i < len; i++){
        if(s[i] == '3'){
            n[1]++;
        }
        if(s[i] == '2'){
            n[0]++;
        }
        int digit = s[i] - '0';
        totalmod9 += digit;
        totalmod9 = totalmod9 % 9;
    }
    
    if(n[0] > 9){
        cout << "YES";
    } else if(n[0]>3&&n[1]>3){
        cout << "YES";
    } else if(n[1]>3 && totalmod9%3==0){
        cout << "YES";
    }else if(searchchanges(totalmod9, n[0], n[1]) == true){
        cout << "YES";
    } else{
        cout << "NO";
    }
    return;
}

int main() {
    int TESTS; cin >> TESTS;
    while (TESTS --> 0) {
        solve();
        cout << '\n';
    }
    return 0;
}