UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#212109#3817. 写字xxcCompile Error//C++915b2024-10-13 11:17:252024-10-13 12:23:42

answer

#include<iostream>
#include<vector>
using namespace std;
const int MAX=0x7fffffff;
int v[500][305];
int lens,lent,ans=MAX;
string s,t;
void f(int l,int k,int sum,bool flag)
{
//	cout<<l<<' '<<k<<' '<<sum<<endl;
	if(k==lent-1&&t[k]==s[l])
	{
		ans=min(ans,sum);
		if(ans==lent-1)
		{
			cout<<ans<<endl;
			exit(0);
		}
		return;
	}
	if(l!=0)
	{
		if(s[l-1]==t[k+1])
		{
			f(l-1,k+1,sum+1,0);
		}
	}
	if(l!=lens-1)
	{
		if(s[l+1]==t[k+1])
		{
			f(l+1,k+1,sum+1,0);
		}
	}
	if(flag==0)
	{
		for(int i=1;i<=v[s[l]][0];i++)
		{
			if(v[s[l]][i]==l) continue;
			f(v[s[l]][i],k,sum+abs(v[s[l]][i]-l),1);
		}
	}
}
int main()
{
	cin>>lens>>lent;
	cin>>s>>t;
	for(int i=0;i<lens;i++)
	{
		v[s[i]][++v[s[i]][0]]=i;
	}
	for(int i=1;i<=v[t[0]][0];i++)
	{
		f(v[t[0]][i],0,0,0);
	}
	if(ans==MAX)
	{
		cout<<-1<<endl;
	}else
	{
		cout<<ans<<endl;
	}
	return 0;
} 

Details

answer.code: In function 'void f(int, int, int, bool)':
answer.code:17:10: error: 'exit' was not declared in this scope
    exit(0);\x0d
          ^
answer.code:40:39: error: 'abs' was not declared in this scope
    f(v[s[l]][i],k,sum+abs(v[s[l]][i]-l),1);\x0d
                                       ^