QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#331884#6366. MessagewullaaaWA 116ms103716kbC++142.3kb2024-02-18 21:12:432024-02-18 21:12:43

Judging History

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

  • [2024-02-18 21:12:43]
  • 评测
  • 测评结果:WA
  • 用时:116ms
  • 内存:103716kb
  • [2024-02-18 21:12:43]
  • 提交

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) r[tot]=i-1,memcpy(alp[tot],vis,sizeof(vis)),vis[t[i]-'a']=true,++tot,l[tot]=i;
        if(ri[t[i]-'a']==i) r[tot]=i,memcpy(alp[tot],vis,sizeof(vis)),vis[t[i]-'a']=false,l[++tot]=i+1;
        // if(le[t[i]-'a']==i) r[tot-1]=i-1,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];
    }
    r[tot]=m;
    // 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){
            if(r[j]-l[j]+1==0&&!alp[j][s[i+1]-'a']) Min(dp[i+1][j],dp[i][j]+w[i+1]);
            if(r[j+1]-l[j+1]+1==0){
                if(!alp[j+1][s[i+1]-'a']) 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: 10084kb

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

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: 23ms
memory: 103592kb

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: 43ms
memory: 103548kb

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: 116ms
memory: 103544kb

input:

soibsuydrizsuvymezuyrewmgwpnzxgyggpzjkdzooisgzbkfqjzkfcklluotqpwganvksoqtzixkfkrtqobdnregwgkxjwzsruvhztscxjyqlhfytomzhxiglxemdhkjnskrsqngojffogrkbygmdgzfwrlhwhhngqpjpepqgynsdybhpuaqhgjroijqofiwnxgxdmhofwsjnmwitruiesefzmabcfsyzrrruidewjowfkwwwqhztsmmtdnejlqhkmbpmknlxijnmzbtqviburbqwufipqsrqplcelovsxz...

output:

You better start from scratch man...

result:

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

Test #6:

score: 0
Accepted
time: 23ms
memory: 103716kb

input:

bbaaaabbbbbabaababbaaabbbabaaaababaababaabababbbbabbbbababaabaaabbabaaaabbbabbaababababbabbbabbaababaaaaaabbabbbababbaabbbabbbabbbabaababaaaaaabaaababbbbbbaabaabaaaaaaabbbaaabaabbbababbbbbabbababaababaabbababbaababbbbbbbbbbbaabbbbbabaaabaabaaabaaaaabaaaabbbbbbbaaaabaabbbababbaaaabbabababbbabbbbabbab...

output:

0

result:

ok single line: '0'

Test #7:

score: 0
Accepted
time: 59ms
memory: 103596kb

input:

hdhlkjabgckjkagfgkigfebfjmdabahajicgkfmblafmfgkiimkjlciiaegbkbkicgklhbhfmclghkleghmckbjliiicmmecldieghfdeghgechcjahdfebkhdigbkklcclieccijaemchbmfcggcjmgbdjhcbacleajjjledkfdjebgdmgahkjigjjighlbedbellabffeeckfbghcblmmgjijdehmcameeledejfijfmfcfkjdjklfldhmkabblcbgebhibkmihelehjccgggjhhbjehfidfmmjdgmmjbf...

output:

0

result:

ok single line: '0'

Test #8:

score: 0
Accepted
time: 103ms
memory: 103644kb

input:

soibsuydrizsuvymezuyrewmgwpnzxgyggpzjkdzooisgzbkfqjzkfcklluotqpwganvksoqtzixkfkrtqobdnregwgkxjwzsruvhztscxjyqlhfytomzhxiglxemdhkjnskrsqngojffogrkbygmdgzfwrlhwhhngqpjpepqgynsdybhpuaqhgjroijqofiwnxgxdmhofwsjnmwitruiesefzmabcfsyzrrruidewjowfkwwwqhztsmmtdnejlqhkmbpmknlxijnmzbtqviburbqwufipqsrqplcelovsxz...

output:

0

result:

ok single line: '0'

Test #9:

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

input:

aaaaaaaaaa
a
670064684 12247274 885150692 755303894 373857482 772871474 451986656 733926307 275101324 732261937

output:

4777621032

result:

ok single line: '4777621032'

Test #10:

score: 0
Accepted
time: 1ms
memory: 9944kb

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaa
807194254 763061330 636628022 447638039 310117480 873320507 134259988 666480259 747042520 231541618 643931761 30317274 158530414 253502390 229547045 438239031 709645547 367432988 755781758 67144518 360508870 862615691 635226301 863755466 104979114 4...

output:

5115514604

result:

ok single line: '5115514604'

Test #11:

score: 0
Accepted
time: 1ms
memory: 7924kb

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaa
768295104 305748099 281563038 518303412 678146171 512832379 509999474 360793781 979858190 884904151 886121576 776530718 147119220 985829130 553994391 500082956 167860347 562080893 520228135 790526162 270707017 179265550 913606870 245853815 83...

output:

21140461276

result:

ok single line: '21140461276'

Test #12:

score: 0
Accepted
time: 1ms
memory: 9992kb

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
684483834 637018127 270602950 736485564 883414052 758886073 266638494 906099301 851227039 479339928 603217972 474167559 537788182 324629484 719852776 8079...

output:

27302362948

result:

ok single line: '27302362948'

Test #13:

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

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

131859070652

result:

ok single line: '131859070652'

Test #14:

score: 0
Accepted
time: 1ms
memory: 12200kb

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

781196173176

result:

ok single line: '781196173176'

Test #15:

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

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

4343956108320

result:

ok single line: '4343956108320'

Test #16:

score: 0
Accepted
time: 5ms
memory: 33580kb

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

18494567762260

result:

ok single line: '18494567762260'

Test #17:

score: 0
Accepted
time: 8ms
memory: 57096kb

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

32209183658799

result:

ok single line: '32209183658799'

Test #18:

score: 0
Accepted
time: 18ms
memory: 80052kb

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

54681136007004

result:

ok single line: '54681136007004'

Test #19:

score: 0
Accepted
time: 22ms
memory: 103192kb

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

29370598770431

result:

ok single line: '29370598770431'

Test #20:

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

input:

aaaabababb
bb
476848657 19478030 860633182 479517749 926931997 990353030 811177212 276072809 44418816 639422667

output:

3786744940

result:

ok single line: '3786744940'

Test #21:

score: 0
Accepted
time: 1ms
memory: 8064kb

input:

baabbbaabbbbbbaaabbabababbbabb
aabbbbbbbbbbbb
596942736 513321407 582182914 466363879 661702687 696876564 738552457 374802663 475543850 315580035 306727219 980454952 485808481 677883937 518967937 895712736 991586358 554417767 795851770 921017576 109301858 423859119 202619045 804565823 583428190 4070...

output:

9486081373

result:

ok single line: '9486081373'

Test #22:

score: 0
Accepted
time: 1ms
memory: 10088kb

input:

bbaaaaababbaabbbabaaaaaaaaaaaaaaabaabaabbabbbbaaaa
bba
517088091 307183015 994179974 164146474 156595248 11692792 656694126 683962150 307132163 246359231 966105863 281059597 304728259 612665622 916423647 405320553 230841790 746930714 950416681 343242506 418374186 670629995 146835514 191417218 469803...

output:

21735754192

result:

ok single line: '21735754192'

Test #23:

score: -100
Wrong Answer
time: 1ms
memory: 8072kb

input:

abbbbabbbbbaaaabaabbbaaabaababaaababaababbbaaaabbaabbbabbaabbaabbbbbabbbbaabaabaabbbaabbaaaabaaabbab
bbbbbbbbbbbbab
224008866 420036954 610760159 229448373 88014692 800505315 190642695 680916401 526205898 463834969 506379052 591268851 942360508 176667947 891525614 324651315 294533169 355712507 94407...

output:

41199447422

result:

wrong answer 1st lines differ - expected: '40969461750', found: '41199447422'