Problem: 2050C - Uninteresting Number
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Time limit exceeded on test 6):
// Jai Ho mere Gurudev Bhagwan Ki

// Jai Jai Shree Radhey Shyam

#include<bits/stdc++.h>

#define int long long int

#define ll long long int

#define pb push_back

#define debug(...) __f (#__VA_ARGS__, __VA_ARGS__)

using namespace std;



/*B U G*/

template <typename Arg1>

void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }

template <typename Arg1, typename... Args>

void __f (const char* names, Arg1&& arg1, Args&&... args){

    const char* comma = strchr (names + 1, ',');

    cout.write (names, comma - names) << " : " << arg1 << " | ";

    __f (comma + 1, args...);

}

/*B U G*/

unordered_map<string, bool> dp;

bool sol(int index, int sum, int n, vector<int> &vec){

    if(index == n) return (sum%9 == 0);

    string key = to_string(index)+'_'+to_string(sum);

    if(dp.find(key) != dp.end()) return dp[key];

    if(sol(index+1, sum, n, vec)) return dp[key] = true;



    if(vec[index] < 4){

        int value = vec[index];

        sum+=(vec[index]*(vec[index]-1));

        vec[index]*=vec[index];

        if(sum%9 == 0) return dp[key] = true;

        if(sol(index+1, sum, n, vec)) return dp[key] = true;

        vec[index] = value;

    }

    return dp[key] = false;

}

void solve() {

    string s; cin>>s; int n = s.size(), sum = 0; 

    vector<int> vec(n);

    for(int i = 0; i<n; ++i){

        vec[i] = s[i] - '0';

        sum+=vec[i];

    }

    dp.clear();

    if(sol(0, sum, n, vec)) cout<<"YES\n";

    else cout<<"NO\n";

}



int32_t main(){

    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    #ifndef ONLINE_JUDGE

    freopen("input.txt", "r", stdin);

    freopen("output.txt", "w", stdout);

    #endif

    int t = 1;

    cin >> t;

    for(int i = 0; i < t; i++){

        solve();

    }

    return 0;

}

Submission (verdict: Time limit exceeded on test 6):
// Jai Ho mere Gurudev Bhagwan Ki

// Jai Jai Shree Radhey Shyam

#include<bits/stdc++.h>

#define int long long int

#define ll long long int

#define pb push_back

#define debug(...) __f (#__VA_ARGS__, __VA_ARGS__)

using namespace std;



/*B U G*/

template <typename Arg1>

void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }

template <typename Arg1, typename... Args>

void __f (const char* names, Arg1&& arg1, Args&&... args){

    const char* comma = strchr (names + 1, ',');

    cout.write (names, comma - names) << " : " << arg1 << " | ";

    __f (comma + 1, args...);

}

/*B U G*/

unordered_map<string, bool> dp;

bool sol(int index, int sum, int n, vector<int> &vec){

    string key = to_string(index)+"_"+to_string(sum);

    if(index == n) return dp[key] = (sum%9 == 0);

    if(sum%9 == 0) return dp[key] = true;

    if(dp.find(key) != dp.end()) return dp[key];

    int real_val = vec[index], real_sum = sum;

    sum+=(vec[index]*(vec[index]-1)); vec[index]*=vec[index];

    if(sum%9 == 0) return dp[key] = true;

    if(sol(index+1, sum, n, vec)) return dp[key] = true;

    vec[index] = real_val, sum = real_sum;

    if(sol(index+1, sum, n, vec)) return dp[key] = true;



    return dp[key] = false;

}

void solve() {

    string s; cin>>s; int n = s.size(), sum = 0;

    vector<int> vec;

    for(int i = 0; i<n; ++i){

        int val = s[i] - '0'; sum+=val;

        if(val != 1 && val < 4) vec.push_back(val);

    }

    dp.clear();

    if(sol(0, sum, vec.size(), vec)) cout<<"YES\n";

    else cout<<"NO\n";

}



int32_t main(){

    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    #ifndef ONLINE_JUDGE

    freopen("input.txt", "r", stdin);

    freopen("output.txt", "w", stdout);

    #endif

    int t = 1;

    cin >> t;

    for(int i = 0; i < t; i++){

        solve();

    }

    return 0;

}