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

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

int main(){
	int t; cin>>t;
	while(t--){
		string s; cin>>s;
		int x= s.size();
		s+= "0000000000";
		for(int i=0;i<(s.size()-i)/10*10;i++){
			for(int j=i+9;j>i;j--){
				if(s[j-1]<s[j]-1){
					swap(s[j-1],s[j]);
					s[j-1]=s[j-1]-1;
				}
			}
		}
		s.erase(s.size() - 10, 10);
		cout<<s<<endl;
	}
}

Submission (verdict: Wrong answer on test 3):
#include<bits/stdc++.h>
using namespace std;

int main(){
	int t; cin>>t;
	while(t--){
		string s; cin>>s;
		int x= s.size();
		s+= "&&&&&&&&&&";
		for(int i=0;i<(s.size()-i)/10*10;i++){
			for(int j=i+9;j>i;j--){
				if(s[j-1]<s[j]-1){
					swap(s[j-1],s[j]);
					s[j-1]=s[j-1]-1;
				}
			}
		}
		s.erase(s.size() - 10, 10);
		cout<<s<<endl;
	}
}
Problem: 2050D - Digital string maximization
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 3):
#include<bits/stdc++.h>
using namespace std;

int main(){
	int t; cin>>t;
	while(t--){
		string s; cin>>s;
		int x= s.size();
		s+= "0000000000";
		for(int i=0;i<(s.size()-i)/10*10;i++){
			for(int j=i+9;j>i;j--){
				if(s[j-1]<s[j]-1){
					swap(s[j-1],s[j]);
					s[j-1]=s[j-1]-1;
				}
			}
		}
		s.erase(s.size() - 10, 10);
		cout<<s<<endl;
	}
}
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int t;
    cin>>t;

    while (t--) {
        string n;
        cin>>n;
        int sum = 0;
        for (char ch : n)    sum += int(ch - '0');

        if (sum % 9 == 0) {
            cout<<"YES"<<endl;
            continue;
        }

        int flag = 0;

        while (n.size() > 0) {
            int digit = n.back() - '0';
            if (digit <= 3)    sum += (digit * (digit - 1));

            if (sum % 9 == 0) {
                flag = 1;
                break;
            }
            n.pop_back();
        }

        if (flag)    cout<<"YES"<<endl;
        else    cout<<"NO"<<endl;
    }

    return 0;
}

Submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int t;
    cin>>t;

    while (t--) {
        string n;
        cin>>n;
        string n1 = n;
        string n2 = n;
        int sum_1 = 0;
        for (char ch : n)    sum_1 += int(ch - '0');
        int sum_2 = sum_1;

        if (sum_1 % 9 == 0) {
            cout<<"YES"<<endl;
            continue;
        }

        int flag_1 = 0;
        int flag_2 = 0;

        while (n1.size() > 0) {
            int digit = n1.back() - '0';
            if (digit <= 3)    sum_1 += (digit * (digit - 1));
            if (sum_1 % 9 == 0) {
                flag_1 = 1;
                break;
            }
            n1.pop_back();
        }

        for (char ch : n) {
            int digit = ch - '0';
            if (digit <= 3)    sum_2 += (digit * (digit - 1));
            if (sum_2 % 9 == 0) {
                flag_2 = 1;
                break;
            }
        }

        if (flag_1 || flag_2)    cout<<"YES"<<endl;
        else    cout<<"NO"<<endl;
    }

    return 0;
}
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int t;
    cin>>t;

    while (t--) {
        string n;
        cin>>n;
        string n1 = n;
        string n2 = n;
        int sum_1 = 0;
        for (char ch : n)    sum_1 += int(ch - '0');
        int sum_2 = sum_1;

        if (sum_1 % 9 == 0) {
            cout<<"YES"<<endl;
            continue;
        }

        int flag_1 = 0;
        int flag_2 = 0;

        while (n1.size() > 0) {
            int digit = n1.back() - '0';
            if (digit <= 3)    sum_1 += (digit * (digit - 1));
            if (sum_1 % 9 == 0) {
                flag_1 = 1;
                break;
            }
            n1.pop_back();
        }

        for (char ch : n) {
            int digit = ch - '0';
            if (digit <= 3)    sum_2 += (digit * (digit - 1));
            if (sum_2 % 9 == 0) {
                flag_2 = 1;
                break;
            }
        }

        if (flag_1 || flag_2)    cout<<"YES"<<endl;
        else    cout<<"NO"<<endl;
    }

    return 0;
}

Submission (verdict: Accepted):
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int t;
    cin>>t;

    while (t--) {
        string n;
        cin>>n;
        string n1 = n;
        string n2 = n;
        int sum_1 = 0, count_2 = 0, count_3 = 0;
        for (char ch : n) {   
            sum_1 += int(ch - '0');
            if (ch == '2')    count_2++;
            if (ch == '3')    count_3++;
        }

        int flag = 0;

        for (int i = 0; i <= count_2; ++i) {
            for (int j = 0; j <= count_3; ++j) {
                int temp_sum = (j * (3) * (2)) + (i * (2) * (1));   
                //digit_count * digit * (digit - 1) = subtartcting digit and adding digit^2 for that count
                //digit can be 2, 3 only since digit^2 < 10; 0 and 1 wont change sum upon squaring.
                //basically squaring and updating sum (updates sum_1 = sum_1 + temp_sum) for each 
                //combination (i, j) to check if updated sum is ever divisible by 9.

                if ((sum_1 + temp_sum) % 9 == 0) {
                    flag = 1;
                    break;
                }
            }
            if (flag)    break;
        }

        if (flag)    cout<<"YES"<<endl;
        else    cout<<"NO"<<endl;
    }

    return 0;
}
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int t;
    cin>>t;

    while (t--) {
        string n;
        cin>>n;
        int sum = 0;
        for (char ch : n)    sum += int(ch - '0');

        if (sum % 9 == 0) {
            cout<<"YES"<<endl;
            continue;
        }

        int flag = 0;

        while (n.size() > 0) {
            int digit = n.back() - '0';
            if (digit <= 3)    sum += (digit * (digit - 1));

            if (sum % 9 == 0) {
                flag = 1;
                break;
            }
            n.pop_back();
        }

        if (flag)    cout<<"YES"<<endl;
        else    cout<<"NO"<<endl;
    }

    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll ksm(ll a,ll b){
    ll res = 1;
    while(b){
        if(b & 1){
            res = res * a;
        }
        a = a * a;
        b >>= 1;
    }
    return res;
}
void solve(){
    ll l,r;
    cin >> l >> r;
    ll a = 0;
    for(ll i = 30;i>=0;i--){
        if(a + ksm(2,i) <= r){
            a += ksm(2,i);
        }
    }
    ll cnt = log2(r);
    ll b = 0;
    for(ll i = cnt;i>=0;i--){
        if((a >> i) & 1){
            b += 0;
        }
        else{
            b += ksm(2,i);
        }
    }
    for(int i = 0;i<=cnt;i++){
        if(b < l){
            b += ksm(2,i);
        }
    }
    ll c = (b == l ? b + 1 : l);
    cout << a << " " << b << " " << c << endl;
}
int main(){
    int t;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve(){
    ll l,r;
    cin >> l >> r;
    bitset<32>x(l),y(r),ans(0);
    int bit = 31;
    for(;~bit;bit--) if(x[bit] ^ y[bit]) break;
    for(int i = 31;i>bit;i--) ans[i] = x[i];
    for(int i = bit;~i;i--){
        if(!(x[i] ^ y[i])) ans[i] = x[i] ^ 1;
    }
    for(int i = bit;~i;i--){
        if(x[i] ^ y[i]){
            ans[i] = 1;
            if(ans.to_ulong() >= y.to_ulong()) ans[i] = 0;
        }
    }
    cout << x.to_ulong() << " " << ans.to_ulong() << " " << y.to_ulong() << endl;
}
int main(){
    int t;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll ksm(ll a,ll b){
    ll res = 1;
    while(b){
        if(b & 1){
            res = res * a;
        }
        a = a * a;
        b >>= 1;
    }
    return res;
}
void solve(){
    ll l,r;
    cin >> l >> r;
    ll a = 0;
    for(ll i = 30;i>=0;i--){
        if(a + ksm(2,i) <= r){
            a += ksm(2,i);
        }
    }
    ll cnt = log2(r);
    ll b = 0;
    for(ll i = cnt;i>=0;i--){
        if((a >> i) & 1){
            b += 0;
        }
        else{
            b += ksm(2,i);
        }
    }
    ll c = (b == l ? b + 1 : l);
    cout << a << " " << b << " " << c << endl;
}
int main(){
    int t;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}

Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll ksm(ll a,ll b){
    ll res = 1;
    while(b){
        if(b & 1){
            res = res * a;
        }
        a = a * a;
        b >>= 1;
    }
    return res;
}
void solve(){
    ll l,r;
    cin >> l >> r;
    ll a = 0;
    for(ll i = 30;i>=0;i--){
        if(a + ksm(2,i) <= r){
            a += ksm(2,i);
        }
    }
    ll cnt = log2(r);
    ll b = 0;
    for(ll i = cnt;i>=0;i--){
        if((a >> i) & 1){
            b += 0;
        }
        else{
            b += ksm(2,i);
        }
    }
    for(int i = 0;i<=cnt;i++){
        if(b < l){
            b += ksm(2,i);
        }
    }
    ll c = (b == l ? b + 1 : l);
    cout << a << " " << b << " " << c << endl;
}
int main(){
    int t;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll ksm(ll a,ll b){
    ll res = 1;
    while(b){
        if(b & 1){
            res = res * a;
        }
        a = a * a;
        b >>= 1;
    }
    return res;
}
void solve(){
    ll l,r;
    cin >> l >> r;
    int cnt = log2(r);
    ll ans = ksm(2,cnt);
    ll res = ans - 2 >= l ? ans - 2:ans + 1;
    cout << ans << " " << ans - 1 << " " << res << endl;
}
int main(){
    int t;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}

Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll ksm(ll a,ll b){
    ll res = 1;
    while(b){
        if(b & 1){
            res = res * a;
        }
        a = a * a;
        b >>= 1;
    }
    return res;
}
void solve(){
    ll l,r;
    cin >> l >> r;
    ll a = 0;
    for(ll i = 30;i>=0;i--){
        if(a + ksm(2,i) <= r){
            a += ksm(2,i);
        }
    }
    ll cnt = log2(r);
    ll b = 0;
    for(ll i = cnt;i>=0;i--){
        if((a >> i) & 1){
            b += 0;
        }
        else{
            b += ksm(2,i);
        }
    }
    ll c = (b == l ? b + 1 : l);
    cout << a << " " << b << " " << c << endl;
}
int main(){
    int t;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll ksm(ll a,ll b){
    ll res = 1;
    while(b){
        if(b & 1){
            res = res * a;
        }
        a = a * a;
        b >>= 1;
    }
    return res;
}
void solve(){
    ll l,r;
    cin >> l >> r;
    int cnt = log2(r);
    ll ans = ksm(2,cnt);
    ll res = ans - 2 >= l ? ans - 2:ans + 1;
    cout << ans << " " << ans - 1 << " " << res << endl;
}
int main(){
    int t;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
typedef long long ll;
#define vi vector<int>
#define pb push_back
#define all(x) x.begin(), x.end()
#define int ll
#define in insert
#define pii pair<int, int>
#define gcd(a, b) __gcd(a, b)
#define fi first
#define se second
#define mp make_pair
#define sz size
#define rall(x) x.rbegin(), x.rend()
void solve() {
  int n;
  cin >> n;

  vi v(n);
  for (int i = 0; i < n; i++)
    cin >> v[i];

  if (n == 1) {
    cout << v[0] << endl;
    return;
  }

  int s = accumulate(v.begin(), v.end(), 0LL);

  if (n == 2) {
    cout << max({(v[0] - v[1]), (v[1] - v[0]), s}) << endl;
    return;
    }

  while (n > 1) {
    vi tmp;

    for (int i = 0; i < n - 1; i++) {
      tmp.push_back(v[i + 1] - v[i]);
    }

    for (int i = 0; i < n; i++)
      v[i] = tmp[i];

    n--;
  }

  int sum = v[0];

  cout << max({sum, -1 * sum, s}) << endl;
}
signed main() {
  cin.tie(0)->sync_with_stdio(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
typedef long long ll;
#define vi vector<int>
#define pb push_back
#define all(x) x.begin(), x.end()
#define int ll
#define in insert
#define pii pair<int, int>
#define gcd(a, b) __gcd(a, b)
#define fi first
#define se second
#define mp make_pair
#define sz size
#define rall(x) x.rbegin(), x.rend()
void solve() {
  int n;
  cin >> n;

  vi v(n);
  for (int i = 0; i < n; i++)
    cin >> v[i];

  if (n == 1) {
    cout << v[0] << endl;
    return;
  }

  int s = accumulate(v.begin(), v.end(), 0LL);

  if (n == 2) {
    cout << max({(v[0] - v[1]), (v[1] - v[0]), s}) << endl;
    return;
    }

  while (n > 1) {
    vi tmp;

    for (int i = 0; i < n - 1; i++) {
      tmp.push_back(v[i + 1] - v[i]);
    }

    for (int i = 0; i < tmp.size(); i++)
      v[i] = tmp[i];

    n--;
  }

  int sum = v[0];

  cout << max({sum, -1 * sum, s}) << endl;
}
signed main() {
  cin.tie(0)->sync_with_stdio(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
typedef long long ll;
#define vi vector<int>
#define pb push_back
#define all(x) x.begin(), x.end()
#define int ll
#define in insert
#define pii pair<int, int>
#define gcd(a, b) __gcd(a, b)
#define fi first
#define se second
#define mp make_pair
#define sz size
#define rall(x) x.rbegin(), x.rend()
void solve() {
  int n, res;
  cin >> n;

  vi v(n);
  for (int i = 0; i < n; i++)
    cin >> v[i];

  if (n == 1) {
    cout << v[0] << endl;
    return;
  }

  res = accumulate(v.begin(), v.end(), 0LL);

  while (v.size() > 1) {
    vi tmp;

    for (int i = 0; i < v.size() - 1; i++) {
      tmp.push_back(v[i + 1] - v[i]);
    }

    for (int i = 0; i < tmp.size(); i++)
      v[i] = tmp[i];

    v.pop_back();

    int a = 0;
    for (int it : tmp)
      a += it;

      res = max(res, max(a, -a));
  }

  int sum = 0;

  for (int it : v)
    sum += it;

  res = max(res, sum);

  cout<<res<<endl;
}
signed main() {
  cin.tie(0)->sync_with_stdio(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
typedef long long ll;
#define vi vector<int>
#define pb push_back
#define all(x) x.begin(), x.end()
#define int ll
#define in insert
#define pii pair<int, int>
#define gcd(a, b) __gcd(a, b)
#define fi first
#define se second
#define mp make_pair
#define sz size
#define rall(x) x.rbegin(), x.rend()
void solve() {
  int n;
  cin >> n;

  vi v(n);
  for (int i = 0; i < n; i++)
    cin >> v[i];

  if (n == 1) {
    cout << v[0] << endl;
    return;
  }

  int s = accumulate(v.begin(), v.end(), 0LL);

  if (n == 2) {
    cout << max({(v[0] - v[1]), (v[1] - v[0]), s}) << endl;
    return;
    }

  while (n > 1) {
    vi tmp;

    for (int i = 0; i < n - 1; i++) {
      tmp.push_back(v[i + 1] - v[i]);
    }

    for (int i = 0; i < n; i++)
      v[i] = tmp[i];

    n--;
  }

  int sum = v[0];

  cout << max({sum, -1 * sum, s}) << endl;
}
signed main() {
  cin.tie(0)->sync_with_stdio(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}

Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
typedef long long ll;
#define vi vector<int>
#define pb push_back
#define all(x) x.begin(), x.end()
#define int ll
#define in insert
#define pii pair<int, int>
#define gcd(a, b) __gcd(a, b)
#define fi first
#define se second
#define mp make_pair
#define sz size
#define rall(x) x.rbegin(), x.rend()
void solve() {
  int n;
  cin >> n;

  vi v(n);
  for (int i = 0; i < n; i++)
    cin >> v[i];

  if (n == 1) {
    cout << v[0] << endl;
    return;
  }

  int s = accumulate(v.begin(), v.end(), 0LL);

  if (n == 2) {
    cout << max({(v[0] - v[1]), (v[1] - v[0]), s}) << endl;
    return;
    }

  while (n > 1) {
    vi tmp;

    for (int i = 0; i < n - 1; i++) {
      tmp.push_back(v[i + 1] - v[i]);
    }

    for (int i = 0; i < tmp.size(); i++)
      v[i] = tmp[i];

    n--;
  }

  int sum = v[0];

  cout << max({sum, -1 * sum, s}) << endl;
}
signed main() {
  cin.tie(0)->sync_with_stdio(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>

using namespace std;
const int INF = 0x3f3f3f3f, N = 1e3 + 5;
int dp[N][N];

int main() {
    int t, n, m;
    string a, b, c;
    cin >> t;
    while (t--) {
        cin >> a;
        cin >> b;
        cin >> c;
        a = "." + a;
        b = ">" + b;
        c = "<" + c;
        dp[0][0] = 0;
        for (int i = 1; i <= (int)a.size(); i++) dp[i][0] = dp[i - 1][0] + (a[i] != c[i]);
        for (int i = 1; i <= (int)b.size(); i++) dp[0][i] = dp[0][i - 1] + (b[i] != c[i]);
        for (int i = 1; i <= (int)a.size(); i++) {
            for (int j = 1; j <= (int)b.size(); j++) {
                dp[i][j] = min(
                    (i + j < (int)a.size() + (int)b.size() && a[i] != c[i + j]) + (i - 1 >= 0 ? dp[i - 1][j] : 0),
                    (i + j < (int)a.size() + (int)b.size() && b[j] != c[i + j]) + (j - 1 >= 0 ? dp[i][j - 1] : 0));
                // cerr << dp[i][j] << " ";
            }
            // cerr << endl;
        }
        cout << dp[(int)a.size()][(int)b.size()] << "\n";
    }
    return 0;
}


Submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>

using namespace std;
const int INF = 0x3f3f3f3f, N = 1e3 + 5;
int dp[N][N];

int main() {
    int t, n, m;
    string a, b, c;
    cin >> t;
    while (t--) {
        cin >> a;
        cin >> b;
        cin >> c;
        a = "." + a;
        b = ">" + b;
        c = "<" + c;
        dp[0][0] = 0;
        for (int i = 1; i <= (int)a.size(); i++) dp[i][0] = dp[i - 1][0] + (a[i] != c[i]);
        for (int i = 1; i <= (int)b.size(); i++) dp[0][i] = dp[0][i - 1] + (b[i] != c[i]);
        for (int i = 1; i <= (int)a.size(); i++) {
            for (int j = 1; j <= (int)b.size(); j++) {
                dp[i][j] = min(
                    (i + j < (int)a.size() + (int)b.size() && a[i] != c[i + j]) + dp[i - 1][j],
                    (i + j < (int)a.size() + (int)b.size() && b[j] != c[i + j]) + dp[i][j - 1]);
                // cerr << dp[i][j] << " ";
            }
            // cerr << endl;
        }
        cout << dp[(int)a.size()][(int)b.size()] << "\n";
    }
    return 0;
}
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>

using namespace std;
const int INF = 0x3f3f3f3f, N = 1e3 + 5;
int dp[N][N];

int main() {
    int t, n, m;
    string a, b, c;
    cin >> t;
    while (t--) {
        cin >> a;
        cin >> b;
        cin >> c;
        a = "." + a;
        b = ">" + b;
        c = "<" + c;
        dp[0][0] = 0;
        for (int i = 1; i <= (int)a.size(); i++) dp[i][0] = dp[i - 1][0] + (a[i] != c[i]);
        for (int i = 1; i <= (int)b.size(); i++) dp[0][i] = dp[0][i - 1] + (b[i] != c[i]);
        for (int i = 1; i <= (int)a.size(); i++) {
            for (int j = 1; j <= (int)b.size(); j++) {
                dp[i][j] = min(
                    (i + j < (int)a.size() + (int)b.size() && a[i] != c[i + j]) + dp[i - 1][j],
                    (i + j < (int)a.size() + (int)b.size() && b[j] != c[i + j]) + dp[i][j - 1]);
                // cerr << dp[i][j] << " ";
            }
            // cerr << endl;
        }
        cout << dp[(int)a.size()][(int)b.size()] << "\n";
    }
    return 0;
}


Submission (verdict: Accepted):
#include <bits/stdc++.h>

using namespace std;
const int INF = 0x3f3f3f3f, N = 1e3 + 5;
int dp[N][N];

int main() {
    int t, n, m;
    string a, b, c;
    cin >> t;
    while (t--) {
        cin >> a;
        cin >> b;
        cin >> c;
        a = "." + a;
        b = ">" + b;
        c = "<" + c;
        dp[0][0] = 0;
        for (int i = 1; i <= (int)a.size() - 1; i++) dp[i][0] = dp[i - 1][0] + (a[i] != c[i]);
        for (int i = 1; i <= (int)b.size() - 1; i++) dp[0][i] = dp[0][i - 1] + (b[i] != c[i]);
        for (int i = 1; i <= (int)a.size() - 1; i++) {
            for (int j = 1; j <= (int)b.size() - 1; j++) {
                dp[i][j] = min(
                    (i + j <= (int)a.size() + (int)b.size() - 2 && a[i] != c[i + j]) + dp[i - 1][j],
                    (i + j <= (int)a.size() + (int)b.size() - 2 && b[j] != c[i + j]) + dp[i][j - 1]);
                // cerr << dp[i][j] << " ";
            }
            // cerr << endl;
        }
        cout << dp[(int)a.size() - 1][(int)b.size() - 1] << "\n";
    }
    return 0;
}
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)


Submission (verdict: Time limit exceeded on test 6):
#include <bits/stdc++.h>

using namespace std;
const int INF = 0x3f3f3f3f;

int calc(string &a, string &b, string &c, int i = 0, int j = 0, int k = 0) {
    if (k == (int)c.size()) return 0;
    int mn = INF;
    if (i < (int)a.size())
        mn = calc(a, b, c, i + 1, j, k + 1) + (a[i] != c[k]);
    if (j < (int)b.size())
        mn = min(mn, calc(a, b, c, i, j + 1, k + 1) + (b[j] != c[k]));
    return mn;
}

int main() {
    int t, n, m;
    string a, b, c;
    cin >> t;
    while (t--) {
        cin >> a;
        cin >> b;
        cin >> c;
        cout << calc(a, b, c) << "\n";
    }
    return 0;
}