QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#331852#6366. MessagewullaaaML 34ms151972kbC++142.1kb2024-02-18 20:31:092024-02-18 20:31:10

Judging History

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

  • [2024-02-18 20:31:10]
  • 评测
  • 测评结果:ML
  • 用时:34ms
  • 内存:151972kb
  • [2024-02-18 20:31:09]
  • 提交

answer

#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
using namespace std;
const int N=2e5+5,P=113;
const ll INF=1e18;
int n,m,w[N],sz[58],id[58][N],pos[58][N];
char s[N],t[N],ss[58][N];
int le[26],ri[26],tot=1,l[58],r[58];
bool vis[26],alp[58][26];
ull pw[N],h[58][N];
ull get(int l,int r,int k){ return h[k][r]-h[k][l-1]*pw[r-l+1]; }
ll dp[N][58],sum[58][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;
    for(int i=1;i<=m;++i){
        if(le[t[i]-'a']==i) vis[t[i]-'a']=true,l[++tot]=i;
        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));
        h[0][i]=h[0][i-1]*P+t[i];
    }
    for(int i=1;i<=tot;++i){
        for(int j=1;j<=n;++j){
            sum[i][j]=sum[i][j-1];
            if(alp[i][s[j]-'a']) ss[i][++sz[i]]=s[j],pos[i][sz[i]]=j,id[i][j]=sz[i];
            else id[i][j]=sz[i]+1,sum[i][j]+=w[j];
        }
        for(int j=1;j<=sz[i];++j) h[i][j]=h[i][j-1]*P+ss[i][j];
    }
    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 i=0;i<=n;++i)
        for(int j=0;j<=tot;++j) 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[j+1][i+1],ed=id[j+1][i+1]+r[j+1]-l[j+1];
                if(ed<=sz[j+1]&&get(st,ed,j+1)==get(l[j+1],r[j+1],0)) Min(dp[pos[j+1][ed]][j+1],dp[i][j]+sum[j+1][pos[j+1][ed]]-sum[j+1][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: 0ms
memory: 22432kb

input:

ababccb
abc
7 2 2 4 3 2 1

output:

7

result:

ok single line: '7'

Test #2:

score: 0
Accepted
time: 0ms
memory: 16076kb

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: 127372kb

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: 34ms
memory: 151972kb

input:

bdabcfbdfcffebebcabbadacbbaeeaffbdedeedfabefdfdbddcecdaaddafdfbbdceccedebcecdfbcfbaafcefeecffdabfaacbeeecfeffaaafaefdcdaaeaeecfafcdadbfbccbdecacfeabdbfcacafebdcfbfbebacbffaecbfbcedccabbdecabaebbbdbcfbaeadfcadfadfaebaddbebfcbefdabdcefbbdaaaabcefedabcabcafedcfadedfdcbbccbffdcfdfcfcdfcfbbdabdbbeecafecc...

output:

You better start from scratch man...

result:

ok single line: 'You better start from scratch man...'

Test #5:

score: -100
Memory Limit Exceeded

input:

soibsuydrizsuvymezuyrewmgwpnzxgyggpzjkdzooisgzbkfqjzkfcklluotqpwganvksoqtzixkfkrtqobdnregwgkxjwzsruvhztscxjyqlhfytomzhxiglxemdhkjnskrsqngojffogrkbygmdgzfwrlhwhhngqpjpepqgynsdybhpuaqhgjroijqofiwnxgxdmhofwsjnmwitruiesefzmabcfsyzrrruidewjowfkwwwqhztsmmtdnejlqhkmbpmknlxijnmzbtqviburbqwufipqsrqplcelovsxz...

output:

You better start from scratch man...

result: