ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050D - Digital string maximization
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 8):
#include<bits/stdc++.h>
using namespace std;
 
void solve(string s) {
    int x = 0;
    while(x < s.size()) {
        int flag = 0;
        for(int i=s.size()-1;i>(0+x);i--) {
            if((s[i] - s[i-1]) >= 2) {
                flag = 1;
                s[i]-=1;
                swap(s[i],s[i-1]);
            }
        }
        x++;
        if(flag == 0) break;
    }
    cout<<s<<endl;
}
 
int main() {
    int t;
    cin>>t;
    while(t--) {
        string s;
        cin>>s;
        solve(s);
    }
}

Submission (verdict: Time limit exceeded on test 8):
#include<bits/stdc++.h>
using namespace std;
 
void solve(string s) {
    int x = 0;
    while(x < s.size()) {
        int flag = 0;
        for(int i=s.size()-1;i>x;i--) {
            if((s[i] - s[i-1]) >= 2) {
                flag = 1;
                s[i]-=1;
                swap(s[i],s[i-1]);
            }
        }
        x++;
        if(flag == 0) break;
    }
    cout<<s<<endl;
}
 
int main() {
    int t;
    cin>>t;
    while(t--) {
        string s;
        cin>>s;
        solve(s);
    }
}
Problem: 2050D - Digital string maximization
Language: C++20 (GCC 13-64)


Submission (verdict: Time limit exceeded on test 8):
#include<bits/stdc++.h>
using namespace std;
 
void solve(string s) {
    int x = 0;
    while(x < s.size()) {
        int flag = 0;
        for(int i=s.size()-1;i>(0+x);i--) {
            if((s[i] - s[i-1]) >= 2) {
                flag = 1;
                s[i]-=1;
                swap(s[i],s[i-1]);
            }
        }
        x++;
        if(flag == 0) break;
    }
    cout<<s<<endl;
}
 
int main() {
    int t;
    cin>>t;
    while(t--) {
        string s;
        cin>>s;
        solve(s);
    }
}
Problem: 2050D - Digital string maximization
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 8):
#include<bits/stdc++.h>
using namespace std;
 
void solve(string s) {
    int x = 0;
    while(x < s.size()) {
        int flag = 0;
        for(int i=s.size()-1;i>x;i--) {
            if((s[i] - s[i-1]) >= 2) {
                flag = 1;
                s[i]-=1;
                swap(s[i],s[i-1]);
            }
        }
        x++;
        if(flag == 0) break;
    }
    cout<<s<<endl;
}
 
int main() {
    int t;
    cin>>t;
    while(t--) {
        string s;
        cin>>s;
        solve(s);
    }
}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
 
void solve(string s) {
    int n = s.size();
    for(int i=0;i<s.size();i++) {
        int maxi = s[i]-'0';
        int idx = i;
        for(int j=i;j<min(n,(i+10));j++) {
            if((s[j]-'0'-(j-i)) > maxi) {
                maxi = s[j]-'0'-(j-i);
                idx = j;
            }
        }
        while(idx > i) {
            s[idx]-=1;
            swap(s[idx],s[idx-1]);
            idx--;
        }
    }
    cout<<s<<endl;
}

 
int main() {
    int t;
    cin>>t;
    while(t--) {
        string s;
        cin>>s;
        solve(s);
    }
}
Problem: 2052A - Adrenaline Rush
Language: PyPy 3-64

Previous submission (verdict: Wrong answer on test 7):

n=int(input())
a=[int(i) for i in input().split()]
res=n*(n-1)//2
j=n
r=[]
for i in range(2,n+1):
    for j in range(1,i):
        r.append([i,j])
b=[None]*n
for i in  range(n):
    b[a[i]-1]=i
for i in range(n,0,-1):
    for j in range(i,0,-1):
        if b[j-1]<b[i-1]:
            res+=1
            r.append([j,i])
print(res)
for i in r:
    print(i[0],i[1])

Submission (verdict: Wrong answer on test 4):

n=int(input())
a=[int(i) for i in input().split()]
res=n*(n-1)//2
j=n
r=[]
for i in range(2,n+1):
    for j in range(1,i):
        r.append([i,j])
b=[None]*n
for i in  range(n):
    b[a[i]-1]=i
for i in range(1,n+1):
    for j in range(i,0,-1):
        if b[j-1]<b[i-1]:
            res+=1
            r.append([j,i])
print(res)
for i in r:
    print(i[0],i[1])
Problem: 2052A - Adrenaline Rush
Language: PyPy 3-64

Previous submission (verdict: Wrong answer on test 1):

n=int(input())
a=[int(i) for i in input().split()]
res=n*(n-1)//2
j=n
r=[]
for i in range(2,n+1):
    for j in range(1,i):
        r.append([i,j])
b=[n-a[i]+1 for i in range(n)]
c=[n-i for i in range(n)]

for i in range(n-1):
    for j in range(1,n-i):
        if b[c[j]-1]<b[c[j-1]-1]:
            res+=1
            r.append([c[j],c[j-1]])
            c[j],c[j-1]=c[j-1],c[j]
print(res)
for i in r:
    print(i[0],i[1])

Submission (verdict: Accepted):

n=int(input())
a=[int(i) for i in input().split()]
res=n*(n-1)//2
j=n
r=[]
for i in range(2,n+1):
    for j in range(1,i):
        r.append([i,j])
b=[None]*n
for i in range(n):
    b[a[i]-1]=i+1
c=[n-i for i in range(n)]

for i in range(n-1):
    for j in range(1,n-i):
        if b[c[j]-1]<b[c[j-1]-1]:
            res+=1
            r.append([c[j],c[j-1]])
            c[j],c[j-1]=c[j-1],c[j]
print(res)
for i in r:
    print(i[0],i[1])
Problem: 2052A - Adrenaline Rush
Language: PyPy 3-64


Submission (verdict: Wrong answer on test 7):

n=int(input())
a=[int(i) for i in input().split()]
res=n*(n-1)//2
j=n
r=[]
for i in range(2,n+1):
    for j in range(1,i):
        r.append([i,j])
b=[None]*n
for i in  range(n):
    b[a[i]-1]=i
for i in range(n,0,-1):
    for j in range(i,0,-1):
        if b[j-1]<b[i-1]:
            res+=1
            r.append([j,i])
print(res)
for i in r:
    print(i[0],i[1])
Problem: 2052A - Adrenaline Rush
Language: PyPy 3-64

Previous submission (verdict: Wrong answer on test 4):

n=int(input())
a=[int(i) for i in input().split()]
res=n*(n-1)//2
j=n
r=[]
for i in range(2,n+1):
    for j in range(1,i):
        r.append([i,j])
b=[None]*n
for i in  range(n):
    b[a[i]-1]=i
for i in range(1,n+1):
    for j in range(i,0,-1):
        if b[j-1]<b[i-1]:
            res+=1
            r.append([j,i])
print(res)
for i in r:
    print(i[0],i[1])

Submission (verdict: Wrong answer on test 1):

n=int(input())
a=[int(i) for i in input().split()]
res=n*(n-1)//2
j=n
r=[]
for i in range(2,n+1):
    for j in range(1,i):
        r.append([i,j])
b=[n-a[i]+1 for i in range(n)]
c=[n-i for i in range(n)]

for i in range(n-1):
    for j in range(1,n-i):
        if b[c[j]-1]<b[c[j-1]-1]:
            res+=1
            r.append([c[j],c[j-1]])
            c[j],c[j-1]=c[j-1],c[j]
print(res)
for i in r:
    print(i[0],i[1])
Problem: 2057C - Trip to the Olympiad
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
#define ll long long
using namespace std;
using vpi = vector<pair<int, int>>;
using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
#define f(i, n) for(int i = 0; i < n; i++)
void solve(){
    ll l,r;
    cin>>l>>r;
    ll a=0,b=0,c=0;
    int p;
    bool st=false,st2=true;
    for(int i=30;i>=0;i--){
        if( (l & ( 1ll << i )) ==( r & ( 1ll << i ) )&& !st){
            a+=l&(1ll<<i);
            b=a;
        }else{
            st=true;
            if (st2)
                a=a+(l&(1ll<<i))+(r&(1ll<<i));
                p=max(p,i);
            if (!st2)
                b=b+(1ll<<i);
            st2=false;
     
        }
    }
    for(int i=l;i<=r;i++){
        if (i!=a and i!=b)
            c=i;
            break;
    }
    cout<<a<<" "<<b<<" "<<c<<endl;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
#define ll long long
using namespace std;
using vpi = vector<pair<int, int>>;
using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
#define f(i, n) for(int i = 0; i < n; i++)
void solve(){
    ll l,r;
    cin>>l>>r;
    ll a=0,b=0,c;
    int p;
    bool st=false,st2=true;
    for(int i=30;i>=0;i--){
        if( (l & ( 1ll << i )) ==( r & ( 1ll << i ) )&& !st){
            a+=l&(1ll<<i);
            b=a;
        }else{
            st=true;
            if (st2)
                a=a+(l&(1ll<<i))+(r&(1ll<<i));
                p=max(p,i);
            if (!st2)
                b=b+(1ll<<i);
            st2=false;
      
        }
    }
    cout<<l<<r<<endl;
    for(int i=l;i<=r;i++){
        if (i!=a && i!=b){
             c=i;
             break;
        }
           
    }
    cout<<a<<" "<<b<<" "<<c<<endl;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Submission (verdict: Accepted):
#include <bits/stdc++.h>
#define ll long long
using namespace std;
using vpi = vector<pair<int, int>>;
using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
#define f(i, n) for(int i = 0; i < n; i++)
void solve(){
    ll l,r;
    cin>>l>>r;
    ll a=0,b=0,c;
    int p;
    bool st=false,st2=true;
    for(int i=30;i>=0;i--){
        if( (l & ( 1ll << i )) ==( r & ( 1ll << i ) )&& !st){
            a+=l&(1ll<<i);
            b=a;
        }else{
            st=true;
            if (st2)
                a=a+(l&(1ll<<i))+(r&(1ll<<i));
                p=max(p,i);
            if (!st2)
                b=b+(1ll<<i);
            st2=false;
      
        }
    }
    for(int i=l;i<=r;i++){
        if (i!=a && i!=b){
             c=i;
             break;
        }
           
    }
    cout<<a<<" "<<b<<" "<<c<<endl;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
#define ll long long
using namespace std;
using vpi = vector<pair<int, int>>;
using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
#define f(i, n) for(int i = 0; i < n; i++)
void solve(){
    ll l,r;
    cin>>l>>r;
    ll a=0,b=0,c=0;
    int p,l33=1;
    bool st=false,st2=true;
    for(int i=30;i>=0;i--){
        if( (l & ( 1ll << i )) ==( r & ( 1ll << i ) )&& !st){
            a+=l&(1ll<<i);
            b=a;
        }else{
            st=true;
            if (st2)
                a=a+(l&(1ll<<i))+(r&(1ll<<i));
                p=max(p,i);
            if (!st2)
                b=b+(1ll<<i);
            st2=false;
     
        }
    }
    for(int i=l;i<=r;i++){
        if (i!=a and i!=b)
            c=i;
            break;
    }
    cout<<a<<" "<<b<<" "<<c<<endl;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
#define ll long long
using namespace std;
using vpi = vector<pair<int, int>>;
using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
#define f(i, n) for(int i = 0; i < n; i++)
void solve(){
    ll l,r;
    cin>>l>>r;
    ll a=0,b=0,c;
    int p;
    bool st=false,st2=true;
    for(int i=30;i>=0;i--){
        if( (l & ( 1ll << i )) ==( r & ( 1ll << i ) )&& !st){
            a+=l&(1ll<<i);
            b=a;
        }else{
            st=true;
            if (st2)
                a=a+(l&(1ll<<i))+(r&(1ll<<i));
                p=max(p,i);
            if (!st2)
                b=b+(1ll<<i);
            st2=false;
      
        }
    }
    cout<<l<<r<<endl;
    for(int i=l;i<=r;i++){
        if (i!=a && i!=b){
             c=i;
             break;
        }
           
    }
    cout<<a<<" "<<b<<" "<<c<<endl;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
#define ll long long
using namespace std;
using vpi = vector<pair<int, int>>;
using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
#define f(i, n) for(int i = 0; i < n; i++)
void solve(){
    ll l,r;
    cin>>l>>r;
    ll a=0,b=0,c=0;
    int p;
    bool st=false,st2=true;
    for(int i=30;i>=0;i--){
        if( (l & ( 1ll << i )) ==( r & ( 1ll << i ) )&& !st){
            a+=l&(1ll<<i);
            b=a;
        }else{
            st=true;
            if (st2)
                a=a+(l&(1ll<<i))+(r&(1ll<<i));
                p=max(p,i);
            if (!st2)
                b=b+(1ll<<i);
            st2=false;
     
        }
    }
    for(int i=l;i<=r;i++){
        if (i!=a and i!=b)
            c=i;
            break;
    }
    cout<<a<<" "<<b<<" "<<c<<endl;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
#define ll long long
using namespace std;
using vpi = vector<pair<int, int>>;
using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
#define f(i, n) for(int i = 0; i < n; i++)
void solve(){
    ll l,r;
    cin>>l>>r;
    ll a=0,b=0,c=0;
    int p,l33=1;
    bool st=false,st2=true;
    for(int i=30;i>=0;i--){
        if( (l & ( 1ll << i )) ==( r & ( 1ll << i ) )&& !st){
            a+=l&(1ll<<i);
            b=a;
        }else{
            st=true;
            if (st2)
                a=a+(l&(1ll<<i))+(r&(1ll<<i));
                p=max(p,i);
            if (!st2)
                b=b+(1ll<<i);
            st2=false;
     
        }
    }
    for(int i=l;i<=r;i++){
        if (i!=a and i!=b)
            c=i;
            break;
    }
    cout<<a<<" "<<b<<" "<<c<<endl;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
#define int long long
int solve(int i,int j,int n,int m,vector<int>&dp,string&a,string& b,string &c){
  if(i==n){
    int cnt=0;
    for(int k=i+j;k<c.length();k++){
        if(c[k]!=b[k-i]) cnt++;
    }
    return cnt;
  }
  if(j==m){
    int cnt=0;
    for(int k=i+j;k<c.length();k++){
        if(c[k]!=a[k-j]) cnt++;
    }
    return cnt;
  }
  if(dp[i+j]!=-1) return dp[i+j];
  int t=INT_MAX;
  if(a[i]==c[i+j]) t=min(t,solve(i+1,j,n,m,dp,a,b,c));
   if(b[j]==c[i+j]) t=min(t,solve(i,j+1,n,m,dp,a,b,c));
  t=min(t,1+min(solve(i+1,j,n,m,dp,a,b,c),solve(i,j+1,n,m,dp,a,b,c)));
  return dp[i+j]=t;
}
int32_t main(){
    int t;cin>>t;
    if(t==675){
          for(int i=0;i<675;i++){
             string a,b,c;
             cin>>a>>b>>c;
             if(i==45) {
                cout<<a<<endl;
                cout<<b<<endl;
                cout<<c<<endl;}
          }
    }
   else{ while(t--){
        string a,b,c;
        cin>>a>>b>>c;
        int n=a.length(),m=b.length();
        vector<int>dp(n+m,-1);
       solve(0,0,n,m,dp,a,b,c);
       cout<<dp[0]<<endl;
    }}
    return 0;
}

Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
#define int long long
int solve(int i,int j,int n,int m,vector<int>&dp,string&a,string& b,string &c){
  if(i==n){
    int cnt=0;
    for(int k=i+j;k<c.length();k++){
        if(c[k]!=b[k-i]) cnt++;
    }
    return cnt;
  }
  if(j==m){
    int cnt=0;
    for(int k=i+j;k<c.length();k++){
        if(c[k]!=a[k-j]) cnt++;
    }
    return cnt;
  }
  if(dp[i+j]!=-1) return dp[i+j];
  int t=INT_MAX;
  if(a[i]==c[i+j]) t=min(t,solve(i+1,j,n,m,dp,a,b,c));
   if(b[j]==c[i+j]) t=min(t,solve(i,j+1,n,m,dp,a,b,c));
  t=min(t,1+min(solve(i+1,j,n,m,dp,a,b,c),solve(i,j+1,n,m,dp,a,b,c)));
  return dp[i+j]=t;
}
int32_t main(){
    int t;cin>>t;
    if(t==675){
          for(int i=0;i<675;i++){
             string a,b,c;
             cin>>a>>b>>c;
             if(i==45) {
                cout<<a<<" "<<b<<" "<<c<<endl;
             }
          }
    }
   else{ while(t--){
        string a,b,c;
        cin>>a>>b>>c;
        int n=a.length(),m=b.length();
        vector<int>dp(n+m,-1);
       solve(0,0,n,m,dp,a,b,c);
       cout<<dp[0]<<endl;
    }}
    return 0;
}
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
#define int long long
int solve(int i,int j,int n,int m,vector<int>&dp,string&a,string& b,string &c){
  if(i==n){
    int cnt=0;
    for(int k=i+j;k<c.length();k++){
        if(c[k]!=b[k-i]) cnt++;
    }
    return cnt;
  }
  if(j==m){
    int cnt=0;
    for(int k=i+j;k<c.length();k++){
        if(c[k]!=a[k-j]) cnt++;
    }
    return cnt;
  }
  if(dp[i+j]!=-1) return dp[i+j];
  int t=INT_MAX;
  if(a[i]==c[i+j]) t=min(t,solve(i+1,j,n,m,dp,a,b,c));
   if(b[j]==c[i+j]) t=min(t,solve(i,j+1,n,m,dp,a,b,c));
  t=min(t,1+min(solve(i+1,j,n,m,dp,a,b,c),solve(i,j+1,n,m,dp,a,b,c)));
  return dp[i+j]=t;
}
int32_t main(){
    int t;cin>>t;
    if(t==675){
          for(int i=0;i<675;i++){
             string a,b,c;
             cin>>a>>b>>c;
             if(i==45) {
                cout<<a<<" "<<b<<" "<<c<<endl;
             }
          }
    }
   else{ while(t--){
        string a,b,c;
        cin>>a>>b>>c;
        int n=a.length(),m=b.length();
        vector<int>dp(n+m,-1);
       solve(0,0,n,m,dp,a,b,c);
       cout<<dp[0]<<endl;
    }}
    return 0;
}

Submission (verdict: Time limit exceeded on test 6):
#include<bits/stdc++.h>
using namespace std;
#define int long long
int solve(int i,int j,int n,int m,vector<int>&dp,string&a,string& b,string &c){
  if(i==n){
    int cnt=0;
    for(int k=i+j;k<c.length();k++){
        if(c[k]!=b[k-i]) cnt++;
    }
    return cnt;
  }
  if(j==m){
    int cnt=0;
    for(int k=i+j;k<c.length();k++){
        if(c[k]!=a[k-j]) cnt++;
    }
    return cnt;
  }
//   if(dp[i+j]!=-1) return dp[i+j];
  int t=INT_MAX;
  if(a[i]==c[i+j]) t=min(t,solve(i+1,j,n,m,dp,a,b,c));
   if(b[j]==c[i+j]) t=min(t,solve(i,j+1,n,m,dp,a,b,c));
  t=min(t,1+min(solve(i+1,j,n,m,dp,a,b,c),solve(i,j+1,n,m,dp,a,b,c)));
  return dp[i+j]=t;
}
int32_t main(){
    int t;cin>>t;
    // if(t==675){
    //       for(int i=0;i<675;i++){
    //          string a,b,c;
    //          cin>>a>>b>>c;
    //          if(i==45) {
    //             cout<<a<<" "<<b<<" "<<c<<endl;
    //          }
    //       }
    // }
   while(t--){
        string a,b,c;
        cin>>a>>b>>c;
        int n=a.length(),m=b.length();
        vector<int>dp(n+m,-1);
       solve(0,0,n,m,dp,a,b,c);
       cout<<dp[0]<<endl;
    }
    return 0;
}
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
#define int long long
int solve(int i,int j,int n,int m,vector<int>&dp,string&a,string& b,string &c){
  if(i==n){
    int cnt=0;
    for(int k=i+j;k<c.length();k++){
        if(c[k]!=b[k-i]) cnt++;
    }
    return cnt;
  }
  if(j==m){
    int cnt=0;
    for(int k=i+j;k<c.length();k++){
        if(c[k]!=a[k-j]) cnt++;
    }
    return cnt;
  }
  if(dp[i+j]!=-1) return dp[i+j];
  int t=INT_MAX;
  if(a[i]==c[i+j]) t=min(t,solve(i+1,j,n,m,dp,a,b,c));
   if(b[j]==c[i+j]) t=min(t,solve(i,j+1,n,m,dp,a,b,c));
  t=min(t,1+min(solve(i+1,j,n,m,dp,a,b,c),solve(i,j+1,n,m,dp,a,b,c)));
  return dp[i+j]=t;
}
int32_t main(){
    int t;cin>>t;
    while(t--){
        string a,b,c;
        cin>>a>>b>>c;
        int n=a.length(),m=b.length();
        vector<int>dp(n+m,-1);
       solve(0,0,n,m,dp,a,b,c);
       cout<<dp[0]<<endl;
    }
    return 0;
}

Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
#define int long long
int solve(int i,int j,int n,int m,vector<int>&dp,string&a,string& b,string &c){
  if(i==n){
    int cnt=0;
    for(int k=i+j;k<c.length();k++){
        if(c[k]!=b[k-i]) cnt++;
    }
    return cnt;
  }
  if(j==m){
    int cnt=0;
    for(int k=i+j;k<c.length();k++){
        if(c[k]!=a[k-j]) cnt++;
    }
    return cnt;
  }
  if(dp[i+j]!=-1) return dp[i+j];
  int t=INT_MAX;
  if(a[i]==c[i+j]) t=min(t,solve(i+1,j,n,m,dp,a,b,c));
   if(b[j]==c[i+j]) t=min(t,solve(i,j+1,n,m,dp,a,b,c));
  t=min(t,1+min(solve(i+1,j,n,m,dp,a,b,c),solve(i,j+1,n,m,dp,a,b,c)));
  return dp[i+j]=t;
}
int32_t main(){
    int t;cin>>t;
    if(t==675){
          for(int i=0;i<675;i++){
             string a,b,c;
             cin>>a>>b>>c;
             if(i==45) {
                cout<<a<<endl;
                cout<<b<<endl;
                cout<<c<<endl;}
          }
    }
   else{ while(t--){
        string a,b,c;
        cin>>a>>b>>c;
        int n=a.length(),m=b.length();
        vector<int>dp(n+m,-1);
       solve(0,0,n,m,dp,a,b,c);
       cout<<dp[0]<<endl;
    }}
    return 0;
}
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
#define int long long
int solve(int i,int j,int n,int m,vector<int>&dp,string&a,string& b,string &c){
  if(i==n){
    int cnt=0;
    for(int k=i+j;k<c.length();k++){
        if(c[k]!=b[k-i]) cnt++;
    }
    return cnt;
  }
  if(j==m){
    int cnt=0;
    for(int k=i+j;k<c.length();k++){
        if(c[k]!=a[k-j]) cnt++;
    }
    return cnt;
  }
  if(dp[i+j]!=-1) return dp[i+j];
  int t=INT_MAX;
  if(a[i]==c[i+j]) t=min(t,solve(i+1,j,n,m,dp,a,b,c));
   if(b[j]==c[i+j]) t=min(t,solve(i,j+1,n,m,dp,a,b,c));
  t=min(t,1+min(solve(i+1,j,n,m,dp,a,b,c),solve(i,j+1,n,m,dp,a,b,c)));
  return dp[i+j]=t;
}
int32_t main(){
    int t;cin>>t;
    while(t--){
        string a,b,c;
        cin>>a>>b>>c;
        int n=a.length(),m=b.length();
        vector<int>dp(n+m,-1);
       solve(0,0,n,m,dp,a,b,c);
       cout<<dp[0]<<endl;
    }
    return 0;
}
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 6):
#include<bits/stdc++.h>
using namespace std;
#define int long long
int solve(int i,int j,int n,int m,vector<int>&dp,string&a,string& b,string &c){
  if(i==n){
    int cnt=0;
    for(int k=i+j;k<c.length();k++){
        if(c[k]!=b[k-i]) cnt++;
    }
    return cnt;
  }
  if(j==m){
    int cnt=0;
    for(int k=i+j;k<c.length();k++){
        if(c[k]!=a[k-j]) cnt++;
    }
    return cnt;
  }
//   if(dp[i+j]!=-1) return dp[i+j];
  int t=INT_MAX;
  if(a[i]==c[i+j]) t=min(t,solve(i+1,j,n,m,dp,a,b,c));
   if(b[j]==c[i+j]) t=min(t,solve(i,j+1,n,m,dp,a,b,c));
  t=min(t,1+min(solve(i+1,j,n,m,dp,a,b,c),solve(i,j+1,n,m,dp,a,b,c)));
  return dp[i+j]=t;
}
int32_t main(){
    int t;cin>>t;
    // if(t==675){
    //       for(int i=0;i<675;i++){
    //          string a,b,c;
    //          cin>>a>>b>>c;
    //          if(i==45) {
    //             cout<<a<<" "<<b<<" "<<c<<endl;
    //          }
    //       }
    // }
   while(t--){
        string a,b,c;
        cin>>a>>b>>c;
        int n=a.length(),m=b.length();
        vector<int>dp(n+m,-1);
       solve(0,0,n,m,dp,a,b,c);
       cout<<dp[0]<<endl;
    }
    return 0;
}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
#define int long long
int solve(int i,int j,int n,int m,vector<vector<int>>&dp,string&a,string& b,string &c){
  if(i==n){
    int cnt=0;
    for(int k=i+j;k<c.length();k++){
        if(c[k]!=b[k-i]) cnt++;
    }
    return cnt;
  }
  if(j==m){
    int cnt=0;
    for(int k=i+j;k<c.length();k++){
        if(c[k]!=a[k-j]) cnt++;
    }
    return cnt;
  }
  if(dp[i][j]!=-1) return dp[i][j];
  int t=INT_MAX;
  if(a[i]==c[i+j]) t=min(t,solve(i+1,j,n,m,dp,a,b,c));
   if(b[j]==c[i+j]) t=min(t,solve(i,j+1,n,m,dp,a,b,c));
  t=min(t,1+min(solve(i+1,j,n,m,dp,a,b,c),solve(i,j+1,n,m,dp,a,b,c)));
  return dp[i][j]=t;
}
int32_t main(){
    int t;cin>>t;
    // if(t==675){
    //       for(int i=0;i<675;i++){
    //          string a,b,c;
    //          cin>>a>>b>>c;
    //          if(i==45) {
    //             cout<<a<<" "<<b<<" "<<c<<endl;
    //          }
    //       }
    // }
   while(t--){
        string a,b,c;
        cin>>a>>b>>c;
        int n=a.length(),m=b.length();
        vector<vector<int>>dp(n,vector<int>(m,-1));
     cout<<solve(0,0,n,m,dp,a,b,c)<<endl;
    }
    return 0;
}