QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#331862#6366. MessagewullaaaWA 136ms103752kbC++142.0kb2024-02-18 20:44:292024-02-18 20:44:30

Judging History

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

  • [2024-02-18 20:44:30]
  • 评测
  • 测评结果:WA
  • 用时:136ms
  • 内存:103752kb
  • [2024-02-18 20:44:29]
  • 提交

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;
    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));
        hh[i]=hh[i-1]*P+t[i];
    }
    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];
                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;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3832kb

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

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: 28ms
memory: 103476kb

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

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: 136ms
memory: 103624kb

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: 39ms
memory: 103752kb

input:

bbaaaabbbbbabaababbaaabbbabaaaababaababaabababbbbabbbbababaabaaabbabaaaabbbabbaababababbabbbabbaababaaaaaabbabbbababbaabbbabbbabbbabaababaaaaaabaaababbbbbbaabaabaaaaaaabbbaaabaabbbababbbbbabbababaababaabbababbaababbbbbbbbbbbaabbbbbabaaabaabaaabaaaaabaaaabbbbbbbaaaabaabbbababbaaaabbabababbbabbbbabbab...

output:

1191742488

result:

wrong answer 1st lines differ - expected: '0', found: '1191742488'