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

Previous submission (verdict: Wrong answer on test 1):
#include <cstdio>
#include <cstring>
#include<bits/stdc++.h>
using namespace std;

#define int long long
#define nl cout<<endl
#define vec vector<int>
#define vecs vector<string>
#define ddv vector<vec>
#define ub upper_bound 
#define lb lower_bound
#define prnt(v) for(auto i:v) cout<<i<<" "; nl
#define inp(v); for(auto &i:v) cin>>i;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define ppb pop_back
#define F first
#define S second
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl

const int N = 2e5;
const int M = 1e9+7;

int factorials[N+1];
int factInv[N+1];
bool isPrime[N+1];

int gcd(int a,int b){ //O(logb)
    if(!b) return a;
    return gcd(b,a%b);
}

int lcm(int a,int b){ //O(logb)
    return (a*b/gcd(a,b)) % M;
}

int binExp(long long a, int b) { //O(logb)
    a %= M;
    int ans = 1;
    while (b) {
        if (b & 1) ans = (ans * 1LL * a) % M;
        a = (a * 1LL * a) % M;
        b >>= 1;
    }
    return ans;
}

int inv(int n){ //O(logM)
    return binExp(n,M-2);
}

void FACT(){ //O(N)
    factorials[0] = 1;
    for (int i = 1; i <= N; i++) {
        factorials[i] = factorials[i - 1] * 1LL * i % M;
    }
}

void FACTINV(){ //O(N)
    for (int i = 0; i <= N; i++) {
        factInv[i] = inv(factorials[i]);
    }
}

void SIEVE(){ //O(NloglogN)

    //Pre-compute

    fill(isPrime, isPrime+N, true);
    isPrime[0]=isPrime[1]=false;

    for(int i = 2; i <= N; ++i){
        if(isPrime[i]){
            for(int j=2*i ; j<=N ; j+=i)
                isPrime[j]=false;
        }
    }
}

long long nCr(int n, int r){ //O(1) excl. Pre-Comp which is O(N).

    // Pre-Compute before using this func.
    // FACT();
    // FACTINV();

    if (r > n) return 0;
    return (factorials[n] * 1LL * factInv[r] % M * factInv[n - r] % M) % M;
}

void solve(){
    string s;
    cin>>s;
    int n = s.length();

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

        for(int j=i+1;j<min(n,i+10);++j){
            if(s[j]-(j-i) > s[r]-(r-i)){
                r=j;
            }
        }

        for(int j=r ; j>i ; --j){
            --s[j];
            swap(s[j],s[j-1]);
        }

        cout<<s<<endl;
    }

    cout<<s<<endl;
}

int32_t main(){
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);

    // FACT();
    // FACTINV();
    // SIEVE();
    
    int t;
    cin>>t;
 
    while(t--){
        solve();
    }
 
    return 0;
}


Submission (verdict: Accepted):
#include <cstdio>
#include <cstring>
#include<bits/stdc++.h>
using namespace std;

#define int long long
#define nl cout<<endl
#define vec vector<int>
#define vecs vector<string>
#define ddv vector<vec>
#define ub upper_bound 
#define lb lower_bound
#define prnt(v) for(auto i:v) cout<<i<<" "; nl
#define inp(v); for(auto &i:v) cin>>i;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define ppb pop_back
#define F first
#define S second
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl

const int N = 2e5;
const int M = 1e9+7;

int factorials[N+1];
int factInv[N+1];
bool isPrime[N+1];

int gcd(int a,int b){ //O(logb)
    if(!b) return a;
    return gcd(b,a%b);
}

int lcm(int a,int b){ //O(logb)
    return (a*b/gcd(a,b)) % M;
}

int binExp(long long a, int b) { //O(logb)
    a %= M;
    int ans = 1;
    while (b) {
        if (b & 1) ans = (ans * 1LL * a) % M;
        a = (a * 1LL * a) % M;
        b >>= 1;
    }
    return ans;
}

int inv(int n){ //O(logM)
    return binExp(n,M-2);
}

void FACT(){ //O(N)
    factorials[0] = 1;
    for (int i = 1; i <= N; i++) {
        factorials[i] = factorials[i - 1] * 1LL * i % M;
    }
}

void FACTINV(){ //O(N)
    for (int i = 0; i <= N; i++) {
        factInv[i] = inv(factorials[i]);
    }
}

void SIEVE(){ //O(NloglogN)

    //Pre-compute

    fill(isPrime, isPrime+N, true);
    isPrime[0]=isPrime[1]=false;

    for(int i = 2; i <= N; ++i){
        if(isPrime[i]){
            for(int j=2*i ; j<=N ; j+=i)
                isPrime[j]=false;
        }
    }
}

long long nCr(int n, int r){ //O(1) excl. Pre-Comp which is O(N).

    // Pre-Compute before using this func.
    // FACT();
    // FACTINV();

    if (r > n) return 0;
    return (factorials[n] * 1LL * factInv[r] % M * factInv[n - r] % M) % M;
}

void solve(){
    string s;
    cin>>s;
    int n = s.length();

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

        for(int j=i+1;j<min(n,i+10);++j){
            if(s[j]-(j-i) > s[r]-(r-i)){
                r=j;
            }
        }

        for(int j=r ; j>i ; --j){
            --s[j];
            swap(s[j],s[j-1]);
        }

        // cout<<s<<endl;
    }

    cout<<s<<endl;
}

int32_t main(){
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);

    // FACT();
    // FACTINV();
    // SIEVE();
    
    int t;
    cin>>t;
 
    while(t--){
        solve();
    }
 
    return 0;
}