Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast,unroll-loops")


#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
 
using llu = unsigned long long;
using ll = long long;
using ld = long double;
 
using vl = vector<ll>;
using sl = set<ll>;
using msl = multiset<ll>;
using ma = map<ll, ll>;
using vvl = vector<vector<ll>>;
using vp = vector<pair<ll, ll>>;
using sp = set<pair<ll, ll>>;
using msp = multiset<pair<ll, ll>>;
 
#define mod 1000000007
#define mod2 998244353
 
#define inf 9223372036854775807
 
#define nfs string::npos
#define maxi(v) max_element(all(v))
#define mini(v) min_element(all(v))
#define lb(n) lower_bound(n)
#define ub(n) upper_bound(n)
#define lbd(v, n) lower_bound(all(v), n)
#define ubd(v, n) upper_bound(all(v), n)
#define fr(i, a, state) for (ll i = a; i <= state; i++)
#define fn(i, a, state) for (ll i = a; i >= state; i--)
#define f(i, n) for (ll i = 0; i < n; i++)
#define fv(i, n) for (ll i = n - 1; i >= 0; i--)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define bs(n, x) bitset<n>(x).to_string()
#define ia(array, n)           \
    ll array[n];               \
    for (ll i = 0; i < n; i++) \
        cin >> array[i];
 
#define no cout << "NO" \
                << "\n"
 
#define yes cout << "YES" \
                 << "\n"
 
void solve()
{
    string s;
    cin>>s;
    ll n=s.size();
    ll count=0;
    f(i,n)
    {
        if(s[i]<s[i+1]-1)
        {
            s[i+1]-=1;
            swap(s[i],s[i+1]);
        }
        else 
        count++;
    }
    f(i,count)
    {
        f(i,n)
    {
        if(s[i]<s[i+1]-1)
        {
            s[i+1]-=1;
            swap(s[i],s[i+1]);
        }
    }
}
  cout<<s<<endl;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    long long tc = 1;
    cin >> tc;
    while (tc--)
        solve();
}

Submission (verdict: Time limit exceeded on test 6):
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast,unroll-loops")


#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
 
using llu = unsigned long long;
using ll = long long;
using ld = long double;
 
using vl = vector<ll>;
using sl = set<ll>;
using msl = multiset<ll>;
using ma = map<ll, ll>;
using vvl = vector<vector<ll>>;
using vp = vector<pair<ll, ll>>;
using sp = set<pair<ll, ll>>;
using msp = multiset<pair<ll, ll>>;
 
#define mod 1000000007
#define mod2 998244353
 
#define inf 9223372036854775807
 
#define nfs string::npos
#define maxi(v) max_element(all(v))
#define mini(v) min_element(all(v))
#define lb(n) lower_bound(n)
#define ub(n) upper_bound(n)
#define lbd(v, n) lower_bound(all(v), n)
#define ubd(v, n) upper_bound(all(v), n)
#define fr(i, a, state) for (ll i = a; i <= state; i++)
#define fn(i, a, state) for (ll i = a; i >= state; i--)
#define f(i, n) for (ll i = 0; i < n; i++)
#define fv(i, n) for (ll i = n - 1; i >= 0; i--)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define bs(n, x) bitset<n>(x).to_string()
#define ia(array, n)           \
    ll array[n];               \
    for (ll i = 0; i < n; i++) \
        cin >> array[i];
 
#define no cout << "NO" \
                << "\n"
 
#define yes cout << "YES" \
                 << "\n"
 
void solve()
{
    string s;
    cin>>s;
    ll n=s.size();
 f(i,n){
    f(i,n)
    {
        if(s[i]<s[i+1]-1)
        {
            s[i+1]-=1;
            swap(s[i],s[i+1]);
        }
    }
 }

  cout<<s<<endl;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    long long tc = 1;
    cin >> tc;
    while (tc--)
        solve();
}