QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#642973 | #6366. Message | yzc358230151 | WA | 3ms | 99584kb | C++14 | 2.6kb | 2024-10-15 17:26:16 | 2024-10-15 17:26:18 |
Judging History
answer
/*
(E)原神https://qoj.ac/download.php?type=attachments&id=1213&r=0
https://qoj.ac/contest/1213/problem/6366
*/
#include<bits/stdc++.h>
using namespace std;
#define gc getchar
#define pc putchar
#define mkp make_pair
#define pb push_back
typedef long long ll;
char s[200010],t[200010];
int ls,lt;
int w[200010];
bool hd[200010];//段首标记
ll smw[200010];
ll dp[60][200010];int dpcnt;
int fst[26],lst[26];
int L=1,R;
int occ[200010],occcnt;
namespace kmp{
int nxt[200010];
char *r;
void kmp(){
int le=R-L+1;
occcnt=0,
r=t+L-1;
for(int i=1;i<=le;++i)
nxt[i]=0;
nxt[0]=-1,
nxt[1]=0;
int j=0;
for(int i=2;i<=le;++i){
while((~j)&&r[j+1]!=r[i])
j=nxt[j];
nxt[i]=++j;
}
j=0;
for(int i=1;i<=ls;++i){
while((~j)&&r[j+1]!=s[i])
j=nxt[j];
++j;
if(j==le)
occ[++occcnt]=i-le+1,
j=nxt[j];
}
}
}
void mkdp(){
++dpcnt,kmp::kmp();
int len=R-L+1;
// printf("doing #%d dp,with area [%d,%d]\n",
// dpcnt,L,R);
// printf("occurs:\n");
// for(int i=1;i<=occcnt;++i)
// printf("[%d,%d],",occ[i],occ[i]+len-1);
// printf("\n");
ll mxfr=-1;int pt=1;
for(int i=1;i<=occcnt;++i){
// for(;pt<occ[i];++pt)
// if(L<=fst[s[pt]-'a']||L>lst[s[pt]-'a'])
// printf("maxxed mxfr at pt=%d\n",pt),
// mxfr=max(mxfr,dp[dpcnt-1][pt]);
// else
// printf("banned mxfr at pt=%d\n",pt),
// mxfr=-1;
for(;pt<occ[i];++pt)
if(L<=fst[s[pt]-'a']||L>lst[s[pt]-'a'])
// printf("maxxed mxfr at pt=%d\n",pt),
mxfr=max(mxfr,dp[dpcnt-1][pt-1]);
else
// printf("banned mxfr at pt=%d\n",pt),
mxfr=-1;
mxfr=max(mxfr,dp[dpcnt-1][occ[i]-1]);
if(~mxfr)
dp[dpcnt][occ[i]+len-1]=mxfr
+smw[occ[i]+len-1]-smw[occ[i]-1];
}
for(int i=2;i<=ls;++i)
if(R+1<=fst[s[i]-'a']||R+1>lst[s[i]-'a'])
dp[dpcnt][i]=
max(dp[dpcnt][i],dp[dpcnt][i-1]);
}
signed main(){
scanf("%s%s",s+1,t+1),
ls=strlen(s+1),
lt=strlen(t+1);
for(int i=1;i<=ls;++i)
scanf("%d",&w[i]),
smw[i]=smw[i-1]+w[i];
for(int i=1;i<=lt;++i){
if(!fst[t[i]-'a'])
fst[t[i]-'a']=i;
lst[t[i]-'a']=i;
}
memset(dp,~0x3f,sizeof(dp));
for(int i=0;i<26;++i)
// printf("'%c' is [%d,%d]",
// i+'a',fst[i],lst[i]),
hd[fst[i]]=hd[lst[i]+1]=1;
hd[lt+1]=1,dp[0][0]=0;
for(R=1;R<=lt;++R)
if(hd[R+1])
mkdp(),
L=R+1;
if(dp[dpcnt][ls]>=0)
printf("%lld",smw[ls]-dp[dpcnt][ls]);
else
fputs("-1\n",stdout);
return 0;
}
/*
必须连续匹配的串。
具体地,新出现的字符在其前划分,其作为段首;
最后的字符在其后划分,其作为段尾。
注意某些字符不能跳过。
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 99584kb
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: 99444kb
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'