Problem: 2050D - Digital string maximization
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 1):
// I AM NOT HERE TO PARTICIPATE, I AM HERE TO DOMINATE

#define JAI ios::sync_with_stdio(false);

#define SHREE cin.tie(NULL);

#define RAM cout.tie(NULL);

#include <bits/stdc++.h>



#define f(i, n, k) for (int i; i < n; i += k)

#define pb push_back

#define ppb pop_back

#define int long long

#define mp make_pair

using namespace std;

using vpi = vector < pair < int, int >> ;

using pi = pair < int, int > ;

using vi = vector < int > ;

using mapi = map < int, int > ;

using vvi = vector < vector < int >> ;

#define ff first

#define ss second

#define all(x) x.begin(), x.end()

#define sz(x)(int)(x).size()

const int inf = 9e17;

const int mod = 1e9 + 7;

#define DEBUG(x) cerr << #x << ": " << x << '\n'

template < typename T, typename Y >

istream & operator >> (istream & is, pair < T, Y > & p)

{

is >> p.first >> p.second;

return is;

}

template < typename T, typename Y >

ostream & operator << (ostream & os, pair < T, Y > p)

{

os << p.first << ' ' << p.second << ' ';

return os;

}

template < typename T >

istream & operator >> (istream & is, vector < T > & v)

{

for (auto & i: v)

is >> i;

return is;

}

template < typename T >

ostream & operator << (ostream & os, vector < T > v)

{

for (auto & i: v)

os << i << ' ';

return os;

}



int power(int base, int ex, int mod) {

int res = 1;

while (ex > 0) {

if (ex % 2 == 1) {

res = (res * base) % mod;

}

base = (base * base) % mod;

ex /= 2;

}

return res;

}



void sol() {

string str;

cin>>str;



int n = str.length();



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

if(str[i] == '0'){

int x1 = 0;

int max_x1 = -1;

int ind1 = i;



for(int j = i+1;j<i+11;j++){

if(j>=n) break;



x1 = (str[j] - '0') - (j-i);



if(x1 > str[i] - '0'){

if(x1 > max_x1){

max_x1 = x1;

ind1 = j;

}

}

}

str[ind1] = (str[ind1] - '0') -ind1+i +'0';

swap(str[i],str[ind1]);

}

}





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



int x = 0;

int max_x = -1;

int ind = i;



for(int j = i+1;j<i+11;j++){

if(j>=n) break;



x = (str[j] - '0') - (j-i);



if(x > str[i] - '0'){

if(x > max_x){

max_x = x;

ind = j;

}

}

}

str[ind] = (str[ind] - '0') -ind+i +'0';

swap(str[i],str[ind]);

}





cout<<str;

}



signed main() {



JAI SHREE RAM



int t;

cin >> t;





while (t--) {





sol();

cout<<endl;

}







}

Submission (verdict: Accepted):
// I AM NOT HERE TO PARTICIPATE, I AM HERE TO DOMINATE

#define JAI ios::sync_with_stdio(false);

#define SHREE cin.tie(NULL);

#define RAM cout.tie(NULL);

#include <bits/stdc++.h>



#define f(i, n, k) for (int i; i < n; i += k)

#define pb push_back

#define ppb pop_back

#define int long long

#define mp make_pair

using namespace std;

using vpi = vector < pair < int, int >> ;

using pi = pair < int, int > ;

using vi = vector < int > ;

using mapi = map < int, int > ;

using vvi = vector < vector < int >> ;

#define ff first

#define ss second

#define all(x) x.begin(), x.end()

#define sz(x)(int)(x).size()

const int inf = 9e17;

const int mod = 1e9 + 7;

#define DEBUG(x) cerr << #x << ": " << x << '\n'

template < typename T, typename Y >

istream & operator >> (istream & is, pair < T, Y > & p)

{

is >> p.first >> p.second;

return is;

}

template < typename T, typename Y >

ostream & operator << (ostream & os, pair < T, Y > p)

{

os << p.first << ' ' << p.second << ' ';

return os;

}

template < typename T >

istream & operator >> (istream & is, vector < T > & v)

{

for (auto & i: v)

is >> i;

return is;

}

template < typename T >

ostream & operator << (ostream & os, vector < T > v)

{

for (auto & i: v)

os << i << ' ';

return os;

}



int power(int base, int ex, int mod) {

int res = 1;

while (ex > 0) {

if (ex % 2 == 1) {

res = (res * base) % mod;

}

base = (base * base) % mod;

ex /= 2;

}

return res;

}



void sol() {

string str;

cin>>str;



int n = str.length();



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



int x1 = 0;

int max_x1 = str[i] - '0';

int ind1 = i;



for(int j = i+1;j<min(n,i+10);j++){



x1 = (str[j] - '0') - (j-i);



if(x1 > str[i] - '0'){

if(x1 > max_x1){

max_x1 = x1;

ind1 = j;

}

}

}

while(ind1 > i){

swap(str[ind1],str[ind1-1]);

ind1--;

}

str[i] =char( max_x1 + '0');

}







cout<<str;

}



signed main() {



JAI SHREE RAM



int t;

cin >> t;





while (t--) {





sol();

cout<<endl;

}







}