QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#217658#6366. MessageliqingyangCompile Error//C++142.3kb2023-10-17 08:24:572023-10-17 08:24:58

Judging History

你现在查看的是最新测评结果

  • [2023-10-17 08:24:58]
  • 评测
  • [2023-10-17 08:24:57]
  • 提交

answer

#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
using namespace std;
int Task,T,n,m,a[200010],p[26],cnt[26],Cnt[26];
char s[200010],t[200010];
vector<int> S[26];
vector<long long> A[26];
long long ans,V[26];
void dfs(int ps,int pt,long long val)
{
	if(val>=ans)
	{
		return;
	}
	if(pt>m)
	{
		ans=val;
		return;
	}
	int minn=1e9;
	for(int i=0;i<26;i++)
	{
		if(Cnt[i]&&Cnt[i]<cnt[i])
		{
			minn=min(minn,S[i][p[i]]);
		}
	}
	int c=t[pt]-'a';
	if(!(Cnt[c]++))
	{
		int P=upper_bound(S[c].begin(),S[c].end(),ps)-S[c].begin();
		for(int i=P;i+cnt[c]<=S[c].size()&&S[c][i]<minn;i++)
		{
			p[c]=i;
			dfs(S[c][p[c]++],pt+1,val-V[c]+A[c][i]+A[c].back()-A[c][i+cnt[c]]);
		}
		Cnt[c]--,p[c]=0;
		return;
	}
	if(S[c][p[c]]>minn)
	{
		Cnt[c]--;
		return;
	}
	dfs(S[c][p[c]++],pt+1,val);
	Cnt[c]--,p[c]--;
}
long long f[200010][110];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
		cin>>n>>m>>s+1>>t+1;
		for(int i=1;i<=n;i++)
		{
			cin>>a[i];
		}
		memset(cnt,0,sizeof(cnt));
		for(int i=1;i<=m;i++)
		{
			cnt[t[i]-'a']++;
		}
		if(m<=100)
		{
			memset(f,0x3f,sizeof(f)),f[0][0]=0;
			for(int i=1;i<=n;i++)
			{
				memset(Cnt,0,sizeof(Cnt));
				for(int j=0;j<=m;j++)
				{
					if(j)
					{
						Cnt[t[j]-'a']++;
					}
					long long v=f[i-1][j];
					if(!Cnt[s[i]-'a']||Cnt[s[i]-'a']==cnt[s[i]-'a'])
					{
						f[i][j]=min(f[i][j],v+a[i]);
					}
					if(s[i]==t[j+1])
					{
						f[i][j+1]=min(f[i][j+1],v);
					}
				}
			}
			cout<<(f[n][m]<1e18?f[n][m]:-1)<<endl;
			continue;
		}
		for(int i=0;i<26;i++)
		{
			S[i].clear(),A[i].clear();
			A[i].push_back(0);
		}
		for(int i=1;i<=n;i++)
		{
			S[s[i]-'a'].emplace_back(i);
			A[s[i]-'a'].emplace_back(A[s[i]-'a'].back()+a[i]);
		}
		bool flag=1;
		long long sum=0;
		for(int i=0;i<26;i++)
		{
			if(cnt[i])
			{
				V[i]=1e18;
				if(S[i].size()<cnt[i])
				{
					flag=0;
					break;
				}
				for(int j=0;j+cnt[i]<=S[i].size();j++)
				{
					V[i]=min(V[i],A[i][j]+A[i].back()-A[i][j+cnt[i]]);
				}
				sum+=V[i];
			}
		}
		if(!flag)
		{
			cout<<-1<<endl;
			continue;
		}
		ans=1e18,dfs(0,1,sum);
		for(int i=0;i<26;i++)
		{
			if(!cnt[i])
			{
				ans+=A[i].back();
			}
		}
		cout<<(ans<1e18?ans:-1)<<endl;
	return 0;
}

Details

answer.code: In function ‘int main()’:
answer.code:89:25: error: continue statement not within a loop
   89 |                         continue;
      |                         ^~~~~~~~
answer.code:123:25: error: continue statement not within a loop
  123 |                         continue;
      |                         ^~~~~~~~