ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)


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

void solve(){
    int n;cin>>n;
    vector<int> a(n+1);bool flag = true;//单调不减 -> 只要有增加就false
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if(a[i]>a[i-1])flag = false;
    }

    if(flag){
        cout<<"NO\n";return;
    }
    
    for(int i=1;i<=n;i++){//每次看到了减少的数字，就回过头 - min()
        if(a[i]<a[i-1] && i>=2){
            a[i-1] -= min(a[i-1],a[i-2]);
            a[i-2] -= min(a[i-1],a[i-2]);
        }
        if(a[i]<a[i-1])flag = true;
    }

    if(flag){
        cout<<"NO\n";
    }else{
        cout<<"YES\n";
    }
}

int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int _;cin>>_;while(_--)
    solve();return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)

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

void solve(){
    int n;cin>>n;
    vector<int> a(n+1);bool flag = true;//单调不减 -> 只要有增加就false
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if(a[i]>a[i-1])flag = false;
    }

    if(flag){
        cout<<"NO\n";return;
    }
    
    for(int i=1;i<=n;i++){//每次看到了减少的数字，就回过头 - min()
        for(int j=2;j<i;j++){
            a[j] -= min(a[j-1],a[j]);
            a[j-1] -= min(a[j-1],a[j]);
        }//2 3 4 1
        if(a[i]<a[i-1])flag = true;
    }

    if(flag){
        cout<<"NO\n";
    }else{
        cout<<"YES\n";
    }
}

int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int _;cin>>_;while(_--)
    solve();return 0;
}

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

void solve(){
    int n;cin>>n;
    vector<int> a(n+1);bool flag = true;//单调不减 -> 只要有增加就false
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if(a[i]>a[i-1])flag = false;
    }

    if(flag){
        cout<<"NO\n";return;
    }
    
    int j=1;
    for(int i=1;i<=n;i++){ //找到最后一个操作的位置再来开始看，这是对o(n^2)的优化，前面都是0没有必要从头来过
        if(a[i]<a[i-1])j = i;
    }
    if(j==1){
        cout<<"YES\n";
        return;
    }

    for(int i = 1;i<j-1;i++){
        int minN = min(a[i],a[i+1]);
        a[i] -= minN;a[i+1] -= minN;
    }
    cout<<(is_sorted(a.begin(),a.end()) ? "YES\n":"NO\n");
}

int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int _;cin>>_;while(_--)
    solve();return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)

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

void solve(){
    int n;cin>>n;
    vector<int> a(n+1);bool flag = true;//单调不减 -> 只要有增加就false
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if(a[i]>a[i-1])flag = false;
    }

    if(flag){
        cout<<"NO\n";return;
    }
    
    for(int i=1;i<=n;i++){//每次看到了减少的数字，就回过头 - min()
        if(a[i]<a[i-1] && i>=2){
            a[i-1] -= min(a[i-1],a[i-2]);
            a[i-2] -= min(a[i-1],a[i-2]);
        }
        if(a[i]<a[i-1])flag = true;
    }

    if(flag){
        cout<<"NO\n";
    }else{
        cout<<"YES\n";
    }
}

int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int _;cin>>_;while(_--)
    solve();return 0;
}

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

void solve(){
    int n;cin>>n;
    vector<int> a(n+1);bool flag = true;//单调不减 -> 只要有增加就false
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if(a[i]>a[i-1])flag = false;
    }

    if(flag){
        cout<<"NO\n";return;
    }
    
    for(int i=1;i<=n;i++){//每次看到了减少的数字，就回过头 - min()
        for(int j=2;j<i;j++){
            a[j] -= min(a[j-1],a[j]);
            a[j-1] -= min(a[j-1],a[j]);
        }//2 3 4 1
        if(a[i]<a[i-1])flag = true;
    }

    if(flag){
        cout<<"NO\n";
    }else{
        cout<<"YES\n";
    }
}

int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int _;cin>>_;while(_--)
    solve();return 0;
}
Problem: 2052A - Adrenaline Rush
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
ll i,j,k,t,n,m;
struct pxy
{
	ll x,y;
};
int main()
{
	cin>>n;
	ll a[n+10],b[n+10];
	map<ll,ll>vv;
	for(i=1;i<=n;i++)cin>>a[i],b[i]=i,vv[b[i]]=i;
	pxy c[100000];
	ll q=0;
	for(i=n;i>=n;i--)
	{
			for(j=vv[b[i]];j>1;j--)
			{
				c[++q].x=b[j],c[q].y=b[j-1];
				vv[b[j]]=j-1;
				vv[b[j-1]]=j;
				swap(b[j],b[j-1]);
			}
			for(j=1;j<i;j++)
			{
				c[++q].x=b[j+1],c[q].y=b[j];
				vv[b[j]]=j+1;
				vv[b[j+1]]=j;
				swap(b[j],b[j+1]);
			}
	}
	cout<<q<<'\n';
	for(i=1;i<=q;i++)
	{
		cout<<c[i].x<<' '<<c[i].y<<'\n';
	}
}

Submission (verdict: Runtime error on test 38):
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
ll i,j,k,t,n,m;
struct pxy
{
	ll x,y;
};
int main()
{
	cin>>n;
	ll a[n+10],b[n+10];
	map<ll,ll>vv;
	for(i=1;i<=n;i++)cin>>a[i],b[i]=i,vv[b[i]]=i;
	pxy c[100000];
	ll q=0;
	for(i=n;i>=1;i--)
	{
			for(j=vv[a[i]];j>1;j--)
			{
				c[++q].x=b[j],c[q].y=b[j-1];
				vv[b[j]]=j-1;
				vv[b[j-1]]=j;
				swap(b[j],b[j-1]);
			}
			for(j=1;j<i;j++)
			{
				c[++q].x=b[j+1],c[q].y=b[j];
				vv[b[j]]=j+1;
				vv[b[j+1]]=j;
				swap(b[j],b[j+1]);
			}
	}
	cout<<q<<'\n';
	for(i=1;i<=q;i++)
	{
		cout<<c[i].x<<' '<<c[i].y<<'\n';
	}
}
Problem: 2052A - Adrenaline Rush
Language: C++17 (GCC 7-32)

Previous submission (verdict: Runtime error on test 38):
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
ll i,j,k,t,n,m;
struct pxy
{
	ll x,y;
};
int main()
{
	cin>>n;
	ll a[n+10],b[n+10];
	map<ll,ll>vv;
	for(i=1;i<=n;i++)cin>>a[i],b[i]=i,vv[b[i]]=i;
	pxy c[100000];
	ll q=0;
	for(i=n;i>=1;i--)
	{
			for(j=vv[a[i]];j>1;j--)
			{
				c[++q].x=b[j],c[q].y=b[j-1];
				vv[b[j]]=j-1;
				vv[b[j-1]]=j;
				swap(b[j],b[j-1]);
			}
			for(j=1;j<i;j++)
			{
				c[++q].x=b[j+1],c[q].y=b[j];
				vv[b[j]]=j+1;
				vv[b[j+1]]=j;
				swap(b[j],b[j+1]);
			}
	}
	cout<<q<<'\n';
	for(i=1;i<=q;i++)
	{
		cout<<c[i].x<<' '<<c[i].y<<'\n';
	}
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
ll i,j,k,t,n,m;
struct pxy
{
	ll x,y;
};
int main()
{
	cin>>n;
	ll a[n+10],b[n+10];
	map<ll,ll>vv;
	for(i=1;i<=n;i++)cin>>a[i],b[i]=i,vv[b[i]]=i;
	pxy c[2000000];
	ll q=0;
	for(i=n;i>=1;i--)
	{
			for(j=vv[a[i]];j>1;j--)
			{
				c[++q].x=b[j],c[q].y=b[j-1];
				vv[b[j]]=j-1;
				vv[b[j-1]]=j;
				swap(b[j],b[j-1]);
			}
			for(j=1;j<i;j++)
			{
				c[++q].x=b[j+1],c[q].y=b[j];
				vv[b[j]]=j+1;
				vv[b[j+1]]=j;
				swap(b[j],b[j+1]);
			}
	}
	cout<<q<<'\n';
	for(i=1;i<=q;i++)
	{
		cout<<c[i].x<<' '<<c[i].y<<'\n';
	}
}
Problem: 2052A - Adrenaline Rush
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
ll i,j,k,t,n,m;
struct pxy
{
	ll x,y;
};
int main()
{
	cin>>n;
	ll a[n+10],b[n+10];
	map<ll,ll>vv;
	for(i=1;i<=n;i++)cin>>a[i],b[i]=i,vv[b[i]]=i;
	pxy c[100000];
	ll q=0;
	for(i=n;i>=n;i--)
	{
			for(j=vv[b[i]];j>1;j--)
			{
				c[++q].x=b[j],c[q].y=b[j-1];
				vv[b[j]]=j-1;
				vv[b[j-1]]=j;
				swap(b[j],b[j-1]);
			}
			for(j=1;j<i;j++)
			{
				c[++q].x=b[j+1],c[q].y=b[j];
				vv[b[j]]=j+1;
				vv[b[j+1]]=j;
				swap(b[j],b[j+1]);
			}
	}
	cout<<q<<'\n';
	for(i=1;i<=q;i++)
	{
		cout<<c[i].x<<' '<<c[i].y<<'\n';
	}
}
Problem: 2050D - Digital string maximization
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 1):
#include<iostream>
#include<string>
using namespace std;
int main()
{
	int t; cin >> t;
	while (t--)
	{
		string str; cin >> str;
		for (int i = 1; i < str.size(); i++)
		{
			if (str[i]!=0&&str[i] - 1 > str[i - 1])
			{
				str[i] -= 1;
				swap(str[i], str[i - 1]);
				i = 1;
			}
		}
		cout << str << endl;
	}
}

Submission (verdict: Runtime error on test 1):
#include<iostream>
#include<string>
using namespace std;
int main()
{
	int t; cin >> t;
	while (t--)
	{
		string str; cin >> str;
		for (int i = 0; i < str.size(); i++)
		{
			if (str[i]!=0&&str[i] - 1 > str[i - 1])
			{
				str[i] -= 1;
				swap(str[i], str[i - 1]);
				i = 0;
			}
		}
		cout << str << endl;
	}
}
Problem: 2050D - Digital string maximization
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Time limit exceeded on test 6):
#include<iostream>
#include<string>
using namespace std;
int main()
{
	int t; cin >> t;
	while (t--)
	{
		string str; cin >> str;
		for (int i = 1; i < str.size(); i++)
		{
			if (str[i]!=0&&str[i] - 1 > str[i - 1])
			{
				str[i] -= 1;
				swap(str[i], str[i - 1]);
				i = 0;
			}
		}
		cout << str << endl;
	}
}

Submission (verdict: Wrong answer on test 1):
#include<iostream>
#include<string>
using namespace std;
int main()
{
	int t; cin >> t;
	while (t--)
	{
		string str; cin >> str;
		for (int i = 1; i < str.size(); i++)
		{
			if (str[i]!=0&&str[i] - 1 > str[i - 1])
			{
				str[i] -= 1;
				swap(str[i], str[i - 1]);
				i = 1;
			}
		}
		cout << str << endl;
	}
}
Problem: 2050D - Digital string maximization
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Time limit exceeded on test 6):
#include<iostream>
#include<string>
using namespace std;
int main()
{
	int t; cin >> t;
	while (t--)
	{
		string str; cin >> str;
		for (int i = 1; i < str.size(); i++)
		{
			if (str[i]!='0' && (str[i] - 1 > str[i - 1]))
			{
				str[i] -= 1;
				swap(str[i], str[i - 1]);
				i = 0;
			}
		}
		cout << str << endl;
	}
}

Submission (verdict: Accepted):
#include<iostream>
#include<string>
using namespace std;
int main()
{
	int t; cin >> t;
	while (t--)
	{
		string str; cin >> str;
		for (int i = 1; i < str.size(); i++)
		{
			if (str[i]!='0' && (str[i] - 1 > str[i - 1]))
			{
				str[i] -= 1;
				swap(str[i], str[i - 1]);
				i -= 1+(i!=1);
			}
		}
		cout << str << endl;
	}
}
Problem: 2050D - Digital string maximization
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Runtime error on test 1):
#include<iostream>
#include<string>
using namespace std;
int main()
{
	int t; cin >> t;
	while (t--)
	{
		string str; cin >> str;
		for (int i = 0; i < str.size(); i++)
		{
			if (str[i]!=0&&str[i] - 1 > str[i - 1])
			{
				str[i] -= 1;
				swap(str[i], str[i - 1]);
				i = 0;
			}
		}
		cout << str << endl;
	}
}

Submission (verdict: Time limit exceeded on test 6):
#include<iostream>
#include<string>
using namespace std;
int main()
{
	int t; cin >> t;
	while (t--)
	{
		string str; cin >> str;
		for (int i = 1; i < str.size(); i++)
		{
			if (str[i]!='0' && (str[i] - 1 > str[i - 1]))
			{
				str[i] -= 1;
				swap(str[i], str[i - 1]);
				i = 0;
			}
		}
		cout << str << endl;
	}
}
Problem: 2050D - Digital string maximization
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Time limit exceeded on test 6):
#include<iostream>
#include<string>
using namespace std;
int main()
{
	int t; cin >> t;
	while (t--)
	{
		string str; cin >> str;
		for (int i = 1; i < str.size(); i++)
		{
			if (str[i]!=0&&str[i] - 1 > str[i - 1])
			{
				str[i] -= 1;
				swap(str[i], str[i - 1]);
				i = 0;
			}
		}
		cout << str << endl;
	}
}
Problem: 2063C - Remove Exactly Two
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 2):
/**
 *  author: xing huan liu kong 
 *  created: 2025-02-13 10:46:57
 *  
 *  即使这个图论(world)大的无边无际
 *  我也会深度优先搜索(dfs)找到你..
**/
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'  
#define point(x) fixed<<setprecision(x)
using namespace std;

#define int long long
typedef pair<int, int> PII;
typedef array<int, 3> arr;

void solve()
{
    int n;
    cin >> n;

    vector<int> p(n, 0);
    vector<vector<int>> e(n);

    for (int i = 0; i < n - 1; i ++ ) {
        int u, v;
        cin >> u >> v;
        u -- , v -- ;
        p[u] ++ , p[v] ++ ;

        e[u].push_back(v);
        e[v].push_back(u);
    }

    int ans = 1;

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

        int idx = -1, res = -1;
        for (int j = 0; j < n; j ++ ) {
            if (p[j] > res) {
                res = p[j];
                idx = j;
            }
        }

        for (auto j : e[idx]) {
            if (p[j] > 0) {
                p[j] -- , p[idx] -- , ans ++ ;
            }
        }
        p[idx] --, ans -- ;
    }

    cout << ans << endl;
}

signed main(void)
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    
    int t = 1;
    cin >> t;

    while(t -- ){
        solve();
    }

    return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
/**
 *  author: xing huan liu kong 
 *  created: 2025-02-13 10:46:57
 *  
 *  即使这个图论(world)大的无边无际
 *  我也会深度优先搜索(dfs)找到你..
**/
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'  
#define point(x) fixed<<setprecision(x)
using namespace std;

#define int long long
typedef pair<int, int> PII;
typedef array<int, 3> arr;

void solve()
{
    int n;
    cin >> n;

    vector<int> p(n, 0);
    vector<vector<int>> e(n);

    for (int i = 0; i < n - 1; i ++ ) {
        int u, v;
        cin >> u >> v;
        u -- , v -- ;
        p[u] ++ , p[v] ++ ;

        e[u].push_back(v);
        e[v].push_back(u);
    }

    int ans = 1;

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

        int idx = -1, res = -1;
        for (int j = 0; j < n; j ++ ) {
            if (p[j] > res) {
                res = p[j];
                idx = j;
            }
        }

        for (auto j : e[idx]) {
            if (p[j] > 0) {
                p[j] -- , p[idx] -- , ans ++ ;
            }
        }
        p[idx] --, ans -- ;
    }

    cout << ans << endl;
}

signed main(void)
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    
    int t = 1;
    cin >> t;

    while(t -- ){
        solve();
    }

    return 0;
}

Submission (verdict: Wrong answer on test 2):
/**
 *  author: xing huan liu kong 
 *  created: 2025-02-13 10:46:57
 *  
 *  即使这个图论(world)大的无边无际
 *  我也会深度优先搜索(dfs)找到你..
**/
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'  
#define point(x) fixed<<setprecision(x)
using namespace std;

#define int long long
typedef pair<int, int> PII;
typedef array<int, 3> arr;

void solve()
{
    int n;
    cin >> n;

    vector<PII> p(n);
    vector<vector<int>> e(n);

    for (int i = 0; i < n - 1; i ++ ) {
        int u, v;
        cin >> u >> v;
        u -- , v -- ;
        p[u].first ++ , p[v].first ++ ;
        p[i].second = i;

        e[u].push_back(v);
        e[v].push_back(u);
    }

    sort(p.rbegin(), p.rend());

    vector<int> f(n, 0);
    for (int i = 0; i < n; i ++ ) {
        f[p[i].second] = i;
    }

    int res = -1;

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

        for (auto j : e[i]) {
            p[f[j]].first -- , ans ++ ;
        }
        ans -- , p[f[i]].first = 0;

        for (int j = 0; j < n; j ++ ) {
            res = max(res, ans + p[i].first - 1);
            if (i + 1 < n && (p[i + 1].first >= p[i].first || p[i + 1].first == 0)) continue;
            else break;
        }
    }

    cout << res << endl;

}

signed main(void)
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    
    int t = 1;
    cin >> t;

    while(t -- ){
        solve();
    }

    return 0;
}
Problem: 2050E - Three Strings
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve(){
	string a, b, s;
	cin >> a >> b >> s;
	s += "  ";
	int lena = a.size(), lenb = b.size();
	vector<vector<int>> dp(1010, vector<int>(1010,0));
	for(int i = 0; i <= lena; i++){
		for(int j = 0; j <= lenb; j++){
			if(s[i+j] == a[i])dp[i+1][j] = max(dp[i+1][j], dp[i][j] + 1);
			else dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
			if(s[i+j] == b[j])dp[i][j+1] = max(dp[i][j+1], dp[i][j] + 1);
			else dp[i][j+1] = max(dp[i][j+1], dp[i][j]);
		}
	}
	cout << s.size() - dp[lena][lenb] << '\n';
}
signed main(){
	ios::sync_with_stdio(false);cin.tie(0);
	int t = 1;
	cin >> t;
	while(t--){
		solve();
	}
	return 0;
}

Submission (verdict: Time limit exceeded on test 5):
#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve(){
	string a, b, s;
	cin >> a >> b >> s;
	s += "  ";
	int lena = a.size(), lenb = b.size();
	vector<vector<int>> dp(1010, vector<int>(1010,0));
	for(int i = 0; i <= lena; i++){
		for(int j = 0; j <= lenb; j++){
			if(s[i+j] == a[i])dp[i+1][j] = max(dp[i+1][j], dp[i][j] + 1);
			else dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
			if(s[i+j] == b[j])dp[i][j+1] = max(dp[i][j+1], dp[i][j] + 1);
			else dp[i][j+1] = max(dp[i][j+1], dp[i][j]);
		}
	}
	cout << s.size() - 2 - dp[lena][lenb] << '\n';
}
signed main(){
	ios::sync_with_stdio(false);cin.tie(0);
	int t = 1;
	cin >> t;
	while(t--){
		solve();
	}
	return 0;
}
Problem: 2050E - Three Strings
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 5):
#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve(){
	string a, b, s;
	cin >> a >> b >> s;
	s += "  ";
	int lena = a.size(), lenb = b.size();
	vector<vector<int>> dp(1010, vector<int>(1010,0));
	for(int i = 0; i <= lena; i++){
		for(int j = 0; j <= lenb; j++){
			if(s[i+j] == a[i])dp[i+1][j] = max(dp[i+1][j], dp[i][j] + 1);
			else dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
			if(s[i+j] == b[j])dp[i][j+1] = max(dp[i][j+1], dp[i][j] + 1);
			else dp[i][j+1] = max(dp[i][j+1], dp[i][j]);
		}
	}
	cout << s.size() - 2 - dp[lena][lenb] << '\n';
}
signed main(){
	ios::sync_with_stdio(false);cin.tie(0);
	int t = 1;
	cin >> t;
	while(t--){
		solve();
	}
	return 0;
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve(){
	string a, b, s;
	cin >> a >> b >> s;
	s += "  ";
	int lena = a.size(), lenb = b.size();
	vector<vector<int>> dp(lena+10, vector<int>(lenb+10,0));
	for(int i = 0; i <= lena; i++){
		for(int j = 0; j <= lenb; j++){
			if(s[i+j] == a[i])dp[i+1][j] = max(dp[i+1][j], dp[i][j] + 1);
			else dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
			if(s[i+j] == b[j])dp[i][j+1] = max(dp[i][j+1], dp[i][j] + 1);
			else dp[i][j+1] = max(dp[i][j+1], dp[i][j]);
		}
	}
	cout << s.size() - 2 - dp[lena][lenb] << '\n';
}
signed main(){
	ios::sync_with_stdio(false);cin.tie(0);
	int t = 1;
	cin >> t;
	while(t--){
		solve();
	}
	return 0;
}
Problem: 2050E - Three Strings
Language: C++20 (GCC 13-64)


Submission (verdict: Time limit exceeded on test 5):
#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve(){
	string a, b, s;
	cin >> a >> b >> s;
	int lena = a.size(), lenb = b.size();
	vector<vector<int>> dp(1010, vector<int>(1010,0));
	for(int i = 0; i <= lena; i++){
		for(int j = 0; j <= lenb; j++){
			if(s[i+j] == a[i])dp[i+1][j] = max(dp[i+1][j], dp[i][j] + 1);
			else dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
			if(s[i+j] == b[j])dp[i][j+1] = max(dp[i][j+1], dp[i][j] + 1);
			else dp[i][j+1] = max(dp[i][j+1], dp[i][j]);
		}
	}
	cout << s.size() - dp[lena][lenb] << '\n';
}
signed main(){
	ios::sync_with_stdio(false);cin.tie(0);
	int t = 1;
	cin >> t;
	while(t--){
		solve();
	}
	return 0;
}
Problem: 2050E - Three Strings
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 5):
#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve(){
	string a, b, s;
	cin >> a >> b >> s;
	int lena = a.size(), lenb = b.size();
	vector<vector<int>> dp(1010, vector<int>(1010,0));
	for(int i = 0; i <= lena; i++){
		for(int j = 0; j <= lenb; j++){
			if(s[i+j] == a[i])dp[i+1][j] = max(dp[i+1][j], dp[i][j] + 1);
			else dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
			if(s[i+j] == b[j])dp[i][j+1] = max(dp[i][j+1], dp[i][j] + 1);
			else dp[i][j+1] = max(dp[i][j+1], dp[i][j]);
		}
	}
	cout << s.size() - dp[lena][lenb] << '\n';
}
signed main(){
	ios::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>
using namespace std;
#define int long long
void solve(){
	string a, b, s;
	cin >> a >> b >> s;
	s += "  ";
	int lena = a.size(), lenb = b.size();
	vector<vector<int>> dp(1010, vector<int>(1010,0));
	for(int i = 0; i <= lena; i++){
		for(int j = 0; j <= lenb; j++){
			if(s[i+j] == a[i])dp[i+1][j] = max(dp[i+1][j], dp[i][j] + 1);
			else dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
			if(s[i+j] == b[j])dp[i][j+1] = max(dp[i][j+1], dp[i][j] + 1);
			else dp[i][j+1] = max(dp[i][j+1], dp[i][j]);
		}
	}
	cout << s.size() - dp[lena][lenb] << '\n';
}
signed main(){
	ios::sync_with_stdio(false);cin.tie(0);
	int t = 1;
	cin >> t;
	while(t--){
		solve();
	}
	return 0;
}
Problem: 2050E - Three Strings
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Runtime error on test 3):
#include<bits/stdc++.h>
using namespace std;
template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &p){return os << '(' << p.first << ", " << p.second << ')';}
template<typename C,typename D = typename enable_if <!is_same<C, string>::value,typename C::value_type>::type>
ostream &operator<<(ostream &os, const C &v){os << '{';string sep;
    for (const D &x : v)os << sep << x, sep = ", ";return os << '}';}
void dbg_out(){cerr << endl;}
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T){cerr << ' ' << H;dbg_out(T...);}
#ifndef ONLINE_JUDGE
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

#define PII pair<int,int>
#define lowbit(x) (x&(-x))
#define INF 0x3f3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#define ll long long
const int mod = 1e9+7;
const int N = 2e3+1000;

int n,m;
string a,b,c;
vector<vector<int>> f;

void solve(){
    cin >> a >> b >> c;
    n=a.length();m=b.length();
    a=" "+a;b=" "+b;c=" "+c;
    dbg(n,m);
    f.resize(n+2);
    for(int i=0;i<=n+1;i++) vector<int>(n+2,inf).swap(f[i]);


    for(int i=0;i<=n;i++){
        for(int j=0;j<=m;j++){
            if(i==0&&j==0) f[i][j]=0;
            else if(i==0){
                f[i][j]=f[i][j-1]+(b[j]!=c[i+j]);
            }else if(j==0){
                f[i][j]=f[i-1][j]+(a[i]!=c[i+j]);
            }else{
                f[i][j]=min(f[i-1][j]+(a[i]!=c[i+j]),f[i][j-1]+(b[j]!=c[i+j]));
            }
        }
    }
    for(int i=0;i<=n;i++){
        for(int j=0;j<=m;j++){
            cerr << f[i][j] << " ";
        }
        cerr << "\n";
    }
    cout << f[n][m];
}
int main(){
#ifndef ONLINE_JUDGE
    freopen("zin.txt","r",stdin);
    freopen("zout.txt","w",stdout);
#endif
    ios::sync_with_stdio(false);std::cin.tie(0);


    int _=1;
    cin >> _;
    // while(cin >> ){
    while(_--){
        solve();
        if(_) cout << "\n";
    }
}
Problem: 2063C - Remove Exactly Two
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+15;
int t,n,ru[N],a[N],b[N],sum;
int main(){
	cin>>t;
	while(t--){
		memset(ru,0,sizeof ru);
		sum=1;
		cin>>n;
		for(int i=1;i<n;i++){
			cin>>a[i]>>b[i];
			 ru[a[i]]++;
			 ru[b[i]]++;
		}
		int mx=-1,f=0;
		for(int i=1;i<=n;i++){
			if(ru[i]>mx){
				mx=ru[i];
				f=i;
			}
		}
		sum+=mx-1;
		for(int i=1;i<n;i++){
			if(a[i]==f) ru[b[i]]--;
			if(b[i]==f) ru[a[i]]--;
		}
	
		mx=-1;
		for(int i=1;i<=n;i++){
			if(ru[i]>mx&&i!=f){
				mx=ru[i];
			}
		}
		sum+=mx-1;
		cout<<sum<<endl;
		
	}
	return 0;
}