QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#640956#6366. MessageJohnAlfnovWA 0ms23996kbC++172.6kb2024-10-14 17:08:212024-10-14 17:08:26

Judging History

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

  • [2024-10-14 17:08:26]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:23996kb
  • [2024-10-14 17:08:21]
  • 提交

answer

#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
char s[200005],t[200005];
int w[200005],wz[105],cnt[105],vv[105],bp[105],ok[105];
int S[26][200005],T[26][200005];
#define ull unsigned long long
ull mo=111339248186143ull;
#define P 262144
ull sm[P<<1],bs[P<<1];
bool vist[200005];
long long zh;
inline void add(int x){
	if(!vist[x])sm[P|x]=s[x],bs[P|x]=mo,zh+=w[x];
	else sm[P|x]=0,bs[P|x]=1,zh-=w[x];
	vist[x]^=1;
	for(int i=(P|x)>>1;i;i>>=1){
		sm[i]=sm[i<<1]*bs[i<<1|1]+sm[i<<1|1],bs[i]=bs[i<<1]*bs[i<<1|1];
	}
}
long long f[200005],mx[800005];
void addd(int l,int r,int o,int x){
	if(l==r){
		mx[o]=f[x];
		return;
	}
	int mid=(l+r)>>1;
	if(x<=mid)addd(l,mid,o<<1,x);
	else addd(mid+1,r,o<<1|1,x);
	mx[o]=max(mx[o<<1],mx[o<<1|1]);
}
long long query(int l,int r,int o,int ll,int rr){
	if(l>=ll&&r<=rr)return mx[o];
	int mid=(l+r)>>1;long long ans=-4e18;
	if(mid>=ll)ans=max(ans,query(l,mid,o<<1,ll,rr));
	if(mid<rr)ans=max(ans,query(mid+1,r,o<<1|1,ll,rr));
	return ans;
}
int main(){
	scanf("%s%s",s+1,t+1);
	int n=strlen(s+1),m=strlen(t+1);
	long long he=0;
	for(int i=1;i<=n;++i){
		scanf("%d",&w[i]);
		he+=w[i];
	}
	for(int i=1;i<=m;++i){
		wz[t[i]-'a']=i,++cnt[t[i]-'a'];
	}
	int tt=0;
	for(int i=0;i<26;++i)if(wz[i]){
		vv[++tt]=wz[i];
	}
	sort(vv+1,vv+tt+1);
	for(int i=0;i<26;++i){
		for(int j=1;j<=n;++j){
			S[i][j]=S[i][j-1];
			if(s[j]-'a'==i){
				T[i][++S[i][j]]=j;
			}
		}
	}
	for(int i=1;i<(P<<1);++i)bs[i]=1;
	memset(f,-63,sizeof(f));
	memset(mx,-63,sizeof(mx));
	for(int k=1;k<=tt;++k){
		int L=vv[k-1]+1,R=vv[k];
		ull mm=0;
		for(int i=L;i<=R;++i){
			mm=mm*mo+t[i];
			++bp[t[i]-'a'];
		}
		zh=0;
		bool fl=0;
		for(int i=1;i<=n;++i){
			int k=s[i]-'a';
			if(bp[k]){
				add(i);
				if(S[k][i]>bp[k])add(T[k][S[k][i]-bp[k]]);
			}
			if(s[i]==t[R]&&sm[1]==mm){
				int mx=1,mn=n;
				for(int j=0;j<26;++j)if(bp[j]){
					if(ok[j])mx=max(mx,T[j][S[j][i]-bp[j]]);
					mn=min(mn,T[j][S[j][i]-bp[j]+1]-1);
				}
				if(L==1)f[i]=zh;
				else if(mx<=mn)f[i]=query(1,n,1,mx,mn)+zh;
				fl|=(f[i]>0);
			}
		}
		if(!fl)break;
		for(int i=0;i<26;++i){
			int L=S[i][n]-bp[i]+1,R=S[i][n];
			for(int j=L;j<=R;++j)add(T[i][j]);
		}
		char t1=t[vv[k-1]],t2=t[vv[k]];
		for(int i=1;i<=n;++i){
			if(s[i]==t1){
				f[i]=-4e18;addd(1,n,1,i);
			}else if(s[i]==t2){
				addd(1,n,1,i);
			}
		}
		for(int i=L;i<=R;++i)--bp[t[i]-'a'],ok[t[i]-'a']=1;
	}
	long long ans=-1;
	for(int i=1;i<=n;++i)if(s[i]==t[m])ans=max(ans,f[i]);
	if(ans<0)puts("-1");
	else printf("%lld\n",he-ans);
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 23844kb

input:

ababccb
abc
7 2 2 4 3 2 1

output:

7

result:

ok single line: '7'

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 23996kb

input:

babab
baab
2 1 3 2 4

output:

-1

result:

wrong answer 1st lines differ - expected: 'You better start from scratch man...', found: '-1'