Problem: 2050C - Uninteresting Number
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 2):
#include "bits/stdc++.h"
#ifndef ONLINE_JUDGE
#include "debug.h"
#else
#define dbg(x...)
#endif
using namespace std;
using ll = long long;
#define int ll
#define endl '\n'
const int mod = 1000000007;
// clang-format off
template<typename typC,typename typD> istream &operator>>(istream &cin,pair<typC,typD> &a) { return cin>>a.first>>a.second; }
template<typename typC> istream &operator>>(istream &cin,vector<typC> &a) { for (auto &x:a) cin>>x; return cin; }
template<typename typC,typename typD> ostream &operator<<(ostream &cout,const pair<typC,typD> &a) { return cout<<a.first<<' '<<a.second; }
template<typename typC,typename typD> ostream &operator<<(ostream &cout,const vector<pair<typC,typD>> &a) { for (auto &x:a) cout<<x<<'\n'; return cout; }
template<typename typC> ostream &operator<<(ostream &cout,const vector<typC> &a) { int n=a.size(); if (!n) return cout; cout<<a[0]; for (int i=1; i<n; i++) cout<<' '<<a[i]; return cout; }
// #define _GLIBCXX_DEBUG
// clang-format on

int dp[100005][10];
bool f(int i, int cur, vector<int> &v, int sum)
{
    if (i >= v.size())
        return 0;
    // dbg(dp[i][cur]);

    if (dp[i][cur] != -1)
        return dp[i][cur];
    int x = cur;
    cur += v[i];
    if ((cur % 9) == (9 - sum))
        return dp[i][cur] = 1;
    x %= 9;
    cur %= 9;
    return dp[i][cur] = f(i + 1, cur, v, sum) || f(i + 1, x, v, sum);
}
void solve()
{
    ll t, m, n, a, b;
    string h;
    cin >> h;
    int sum = 0;
    vector<int> v;
    for (char &c : h)
    {
        int x = c - '0';
        if (x <= 3)
        {
            if (x == 2)
                v.push_back(2);
            if (x == 3)
                v.push_back(6);
        }
        sum += x;
    }
    sum %= 9;
    dbg(sum, v);
    if (!sum)
    {
        cout << "YES" << endl;
        return;
    }
    memset(dp, -1, sizeof(dp));
    if (f(0, 0, v, sum))
    {
        cout << "YES" << endl;
    }
    else
        cout << "NO" << endl;
}
int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int t;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

Submission (verdict: Time limit exceeded on test 6):
#include "bits/stdc++.h"
#ifndef ONLINE_JUDGE
#include "debug.h"
#else
#define dbg(x...)
#endif
using namespace std;
using ll = long long;
#define int ll
#define endl '\n'
const int mod = 1000000007;
// clang-format off
template<typename typC,typename typD> istream &operator>>(istream &cin,pair<typC,typD> &a) { return cin>>a.first>>a.second; }
template<typename typC> istream &operator>>(istream &cin,vector<typC> &a) { for (auto &x:a) cin>>x; return cin; }
template<typename typC,typename typD> ostream &operator<<(ostream &cout,const pair<typC,typD> &a) { return cout<<a.first<<' '<<a.second; }
template<typename typC,typename typD> ostream &operator<<(ostream &cout,const vector<pair<typC,typD>> &a) { for (auto &x:a) cout<<x<<'\n'; return cout; }
template<typename typC> ostream &operator<<(ostream &cout,const vector<typC> &a) { int n=a.size(); if (!n) return cout; cout<<a[0]; for (int i=1; i<n; i++) cout<<' '<<a[i]; return cout; }
// #define _GLIBCXX_DEBUG
// clang-format on

bool f(int i, int cur, vector<int> &v, int sum, vector<vector<int>> &dp)
{
    if (i >= v.size())
        return 0;
    // dbg(dp[i][cur]);

    if (dp[i][cur] != -1)
        return dp[i][cur];
    int x = cur;
    cur += v[i];
    x %= 9;
    cur %= 9;
    if (cur == (9 - sum))
        return dp[i][cur] = 1;
    return dp[i][cur] = f(i + 1, cur, v, sum, dp) || f(i + 1, x, v, sum, dp);
}
void solve()
{
    ll t, m, n, a, b;
    string h;
    cin >> h;
    int sum = 0;
    vector<int> v;
    for (char &c : h)
    {
        int x = c - '0';
        if (x <= 3)
        {
            if (x == 2)
                v.push_back(2);
            if (x == 3)
                v.push_back(6);
        }
        sum += x;
    }
    sum %= 9;
    dbg(sum, v);
    if (!sum)
    {
        cout << "YES" << endl;
        return;
    }
    vector<vector<int>> dp(v.size() + 1, vector<int>(10, -1));
    if (f(0, 0, v, sum, dp))
    {
        cout << "YES" << endl;
    }
    else
        cout << "NO" << endl;
}
int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int t;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}