QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#393331 | #6366. Message | zjy0001 | WA | 1ms | 9776kb | C++14 | 2.1kb | 2024-04-18 15:17:48 | 2024-04-18 15:17:49 |
Judging History
answer
#include<bits/stdc++.h>
#define LL long long
#define LLL __int128
#define uint unsigned
#define ldb long double
#define uLL unsigned long long
using namespace std;
const int N=2e5+5,M=60;const LL INF=1e18;
int n,m,An,Al[M],Ar[M],a[N],Q[N],id[N],kmp[N],L[26],R[26];string S,T;
bool vs[26],vx[M][26];LL pre[N],dp[N],dq[N];
signed main(){
cin.tie(0)->sync_with_stdio(0);
cin>>S>>T,n=S.length(),m=T.length(),S=' '+S+' ',T=' '+T+' ';
for(int i=1;i<=n;++i)cin>>a[i];
fill(L,L+26,m+1),fill(R,R+26,0);
for(int i=1;i<=m;++i)
L[T[i]-'a']=min(L[T[i]-'a'],i),
R[T[i]-'a']=max(R[T[i]-'a'],i);
Al[++An]=1;
for(int i=1;i<=m;++i){
if(L[T[i]-'a']==i)Ar[An]=i-1,copy(vs,vs+26,vx[An]),vs[T[i]-'a']=1,Al[++An]=i;
if(R[T[i]-'a']==i)Ar[An]=i,copy(vs,vs+26,vx[An]),vs[T[i]-'a']=0,Al[++An]=i+1;
}
Ar[An]=m;
fill(dq,dq+n+1,INF);
for(int i=0;i<=An;++i){
copy(dq,dq+n+1,dp);
fill(dq,dq+n+1,INF);
if(i<2)dp[0]=0;
int q=0;
for(int j=1;j<=n;++j)
if(vx[i+1][S[j]-'a'])Q[id[j]=++q]=j,pre[j]=pre[j-1];
else id[j]=q+1,pre[j]=pre[j-1]+a[j];
const int lp=Al[i+1],rp=Ar[i+1];
for(int i=2,j=0;i<=rp-lp+1;++i){
for(;j&&T[lp+i-1]!=T[lp+j];j=kmp[j]);
kmp[i]=(j+=(T[lp+i-1]==T[lp+j]));
}
int cur=1,pos=0;
const auto KMP=[&](const int&n){
for(;cur<=n;++cur){
for(;pos&&(pos>rp-lp||T[lp+pos]!=S[Q[cur]]);pos=kmp[pos]);
pos+=(T[lp+pos]==S[Q[cur]]);
}
return pos;
};
for(int j=0;j<=n;++j)if(dp[j]<INF){
if(!vx[i][S[j+1]-'a'])dp[j+1]=min(dp[j+1],dp[j]+a[j+1]);
if(Al[i+1]>Ar[i+1]){
if(!vx[i][S[j+1]-'a'])dq[j+1]=min(dq[j+1],dp[j]+a[j+1]);
dq[j]=min(dq[j],dp[j]);
}
else if(j<n){
int l=id[j+1],r=id[j+1]+rp-lp;
if(r<=q&&KMP(r)==rp-lp+1)dq[Q[r]]=min(dq[Q[r]],dp[j]+pre[Q[r]]-pre[j]);
}
}
}
if(dp[n]<INF)cout<<dp[n];else cout<<-1;
return 0;
}
/*
*/
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 9776kb
input:
ababccb abc 7 2 2 4 3 2 1
output:
7
result:
ok single line: '7'
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 5696kb
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'