Source Code
#include <bits/stdc++.h>
using namespace std;
int dp[101][10000];
int t,v2,v1,d;
int INF = 1e9;
int path(int time,int speed){
	if(speed <1)
		return -INF;
	if(dp[time][speed] != -1)
		return dp[time][speed];
	if(time == t){
		if(speed == v2){
			return speed;
		}
		else
			return -INF;
	}
	int y = -INF;
	for(int i = -d; i<= d; i++){
		y = max(speed+path(time+1,speed+i),y);
	}
	dp[time][speed] = y;
	return y;
}
int main(){
	
	///*
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin); //file input.txt is opened in reading mode i.e "r"
	freopen("output.txt","w",stdout);  //file output.txt is opened in writing mode i.e "w"
	#endif
	//*/
	int t,n;
	cin>>t;
	while(t--){
		cin>>n;
		string s,f;
		cin>>s;
		cin>>f;
		if(s != f)
			cout<<1<<endl;
		else
			cout<<0<<endl;
	}

}
Copy
Split and Swap Duukh
GNU G++17
50 ms
908 KB
Accepted