UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#212137#3817. 写字huangyuhangCompile Error//C++899b2024-10-13 11:30:422024-10-13 12:26:11

answer

#include<bits/stdc++.h>
using namespace std;
int n,m;
string s,t;
map<char,vector<int>>mp;
int ans;
void DFS(int p1,int res,int p2)//pos1:S,pos2:T
{
	if(res>ans)
		return;
	if(p2==m)
	{
		ans=min(res,ans);
		return;
	}
	bool flag=false;;
	if(p1>0&&t[p2]==t[p1-1])
	{
		flag=true;
		DFS(p1-1,res+1,p2+1);
	}
	if(p1<n-1&&t[p2]==s[p1+1])
	{
		flag=true;
		DFS(p1+1,res+1,p2+1);		
	}
	if(!flag)
	{
		for(auto p:mp[t[p2]])
		{
			if(p==p1)
				continue;
			if(p<n-1&&t[p2]==s[p+1]||p>0&&t[p2]==s[p-1])
				DFS(p,res+abs(p-p1),p2);
		}
	}
}
int main()
{
	scanf("%d %d",&n,&m);
	cin>>s;
	cin>>t;
	for(int i=0;i<n;i++)
	{
		mp[s[i]].push_back(i);
	}
	for(int i=0;i<m;i++)
		if(!mp.count(t[i]))
		{
			cout<<-1;
			return 0;
		}
	ans=INT_MAX;
	for(auto p:mp[t[0]])
	{
		DFS(p,0,1);
	}
	if(ans==INT_MAX)
		cout<<-1;
	else
		cout<<ans;
	return 0;
}

Details

answer.code:5:20: error: '>>' should be '> >' within a nested template argument list
 map<char,vector<int>>mp;\x0d
                    ^
answer.code: In function 'void DFS(int, int, int)':
answer.code:29:12: error: 'p' does not name a type
   for(auto p:mp[t[p2]])\x0d
            ^
answer.code:36:2: error: expected ';' before '}' token
  }\x0d
  ^
answer.code:36:2: error: expected primary-expression before '}' token
answer.code:36:2: error: expected ';' before '}' token
answer.code:36:2: error: expected ...