QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#331871 | #6366. Message | wullaaa | WA | 107ms | 103652kb | C++14 | 2.2kb | 2024-02-18 20:54:27 | 2024-02-18 20:54:29 |
Judging History
answer
#include<bits/stdc++.h>
#define ull unsigned long long
#define pb push_back
#define ll long long
using namespace std;
const int N=2e5+5,P=113;
const ll INF=1e18;
int n,m,w[N],sz,id[N],pos[N];
char s[N],t[N],ss[N];
int le[26],ri[26],tot=1,l[58],r[58];
bool vis[26],alp[58][26];
ull pw[N],h[N],hh[N];
ull get(int l,int r,int k){
if(!k) return hh[r]-hh[l-1]*pw[r-l+1];
return h[r]-h[l-1]*pw[r-l+1];
}
ll dp[N][58],sum[N];
void Min(ll &x,ll y){ x=x<y?x:y; }
int main(){
scanf("%s\n%s",s+1,t+1),n=strlen(s+1),m=strlen(t+1);
pw[0]=1; for(int i=1;i<=n;++i) scanf("%d",&w[i]),pw[i]=pw[i-1]*P;
for(int i=1;i<=m;++i) (!le[t[i]-'a'])&&(le[t[i]-'a']=i),ri[t[i]-'a']=i;
l[1]=1; for(int i=1;i<=m;++i){
if(le[t[i]-'a']==i) vis[t[i]-'a']=true,++tot,l[tot]=r[tot]=i,memcpy(alp[tot],vis,sizeof(vis));
if(ri[t[i]-'a']==i) r[tot]=i,memcpy(alp[tot],vis,sizeof(vis)),vis[t[i]-'a']=false,r[tot]=i,++tot,l[tot]=i+1,r[tot]=i,memcpy(alp[tot],vis,sizeof(vis));
hh[i]=hh[i-1]*P+t[i];
}
// for(int i=1;i<=tot;++i) cout<<i<<": "<<l[i]<<" "<<r[i]<<" "<<alp[i][0]<<endl;
for(int i=0;i<=n;++i) for(int j=0;j<=tot;++j) dp[i][j]=INF;
dp[0][0]=dp[0][1]=0;
for(int j=0;j<=tot;++j){
sz=0; for(int i=1;i<=n;++i){
sum[i]=sum[i-1];
if(alp[j+1][s[i]-'a']) ss[++sz]=s[i],pos[sz]=i,id[i]=sz;
else id[i]=sz+1,sum[i]+=w[i];
}
for(int i=1;i<=sz;++i) h[i]=h[i-1]*P+ss[i];
for(int i=0;i<=n;++i) if(dp[i][j]<INF){
// cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
if(r[j]-l[j]+1==0&&!alp[j][i+1]) Min(dp[i+1][j],dp[i][j]+w[i+1]);
if(r[j+1]-l[j+1]+1==0){
if(!alp[j+1][i+1]) Min(dp[i+1][j+1],dp[i][j]+w[i+1]);
Min(dp[i][j+1],dp[i][j]);
}else{
int st=id[i+1],ed=id[i+1]+r[j+1]-l[j+1];
// cout<<"*"<<st<<" "<<ed<<" "<<sz<<" "<<(get(st,ed,j+1)==get(l[j+1],r[j+1],0))<<endl;
if(ed<=sz&&get(st,ed,j+1)==get(l[j+1],r[j+1],0)) Min(dp[pos[ed]][j+1],dp[i][j]+sum[pos[ed]]-sum[i]);
}
}
}
ll Sum=0;
if(dp[n][tot]==INF) puts("You better start from scratch man...");
else printf("%lld\n",dp[n][tot]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 9944kb
input:
ababccb abc 7 2 2 4 3 2 1
output:
7
result:
ok single line: '7'
Test #2:
score: 0
Accepted
time: 1ms
memory: 9924kb
input:
babab baab 2 1 3 2 4
output:
You better start from scratch man...
result:
ok single line: 'You better start from scratch man...'
Test #3:
score: 0
Accepted
time: 24ms
memory: 103652kb
input:
bbaaaabbbbbabaababbaaabbbabaaaababaababaabababbbbabbbbababaabaaabbabaaaabbbabbaababababbabbbabbaababaaaaaabbabbbababbaabbbabbbabbbabaababaaaaaabaaababbbbbbaabaabaaaaaaabbbaaabaabbbababbbbbabbababaababaabbababbaababbbbbbbbbbbaabbbbbabaaabaabaaabaaaaabaaaabbbbbbbaaaabaabbbababbaaaabbabababbbabbbbabbab...
output:
You better start from scratch man...
result:
ok single line: 'You better start from scratch man...'
Test #4:
score: 0
Accepted
time: 40ms
memory: 103460kb
input:
bdabcfbdfcffebebcabbadacbbaeeaffbdedeedfabefdfdbddcecdaaddafdfbbdceccedebcecdfbcfbaafcefeecffdabfaacbeeecfeffaaafaefdcdaaeaeecfafcdadbfbccbdecacfeabdbfcacafebdcfbfbebacbffaecbfbcedccabbdecabaebbbdbcfbaeadfcadfadfaebaddbebfcbefdabdcefbbdaaaabcefedabcabcafedcfadedfdcbbccbffdcfdfcfcdfcfbbdabdbbeecafecc...
output:
You better start from scratch man...
result:
ok single line: 'You better start from scratch man...'
Test #5:
score: 0
Accepted
time: 107ms
memory: 103504kb
input:
soibsuydrizsuvymezuyrewmgwpnzxgyggpzjkdzooisgzbkfqjzkfcklluotqpwganvksoqtzixkfkrtqobdnregwgkxjwzsruvhztscxjyqlhfytomzhxiglxemdhkjnskrsqngojffogrkbygmdgzfwrlhwhhngqpjpepqgynsdybhpuaqhgjroijqofiwnxgxdmhofwsjnmwitruiesefzmabcfsyzrrruidewjowfkwwwqhztsmmtdnejlqhkmbpmknlxijnmzbtqviburbqwufipqsrqplcelovsxz...
output:
You better start from scratch man...
result:
ok single line: 'You better start from scratch man...'
Test #6:
score: -100
Wrong Answer
time: 26ms
memory: 103592kb
input:
bbaaaabbbbbabaababbaaabbbabaaaababaababaabababbbbabbbbababaabaaabbabaaaabbbabbaababababbabbbabbaababaaaaaabbabbbababbaabbbabbbabbbabaababaaaaaabaaababbbbbbaabaabaaaaaaabbbaaabaabbbababbbbbabbababaababaabbababbaababbbbbbbbbbbaabbbbbabaaabaabaaabaaaaabaaaabbbbbbbaaaabaabbbababbaaaabbabababbbabbbbabbab...
output:
532925029
result:
wrong answer 1st lines differ - expected: '0', found: '532925029'