QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#332364 | #6366. Message | xcyyyyy | WA | 109ms | 103632kb | C++14 | 1.9kb | 2024-02-19 14:51:20 | 2024-02-19 14:51:21 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define SN 200005
int N,n,m,c[SN];
char s[SN],t[SN];
int num;
int vis[200];
pair<int,int> x[60];
unsigned int C,X;int nxt[SN],S[SN],T[SN],lc[SN];
ll f[SN][60],pre[SN];
int main(){
srand(time(0));
scanf("%s%s",s+1,t+1);N=strlen(s+1),m=strlen(t+1);
for(int i=1;i<=N;i++)scanf("%d",&c[i]);
memset(vis,0,sizeof(vis));
for(int i=1;i<=m;i++)if(!vis[t[i]])vis[t[i]]=1,x[++num]={i,t[i]};
memset(vis,0,sizeof(vis));
for(int i=m;i;i--)if(!vis[t[i]])vis[t[i]]=1,x[++num]={i,t[i]};
sort(x+1,x+1+num);num=unique(x+1,x+1+num)-x-1;
memset(f,-0x3f,sizeof(f));
for(int i=0;i<=N;i++)f[i][0]=0;
x[num+1].first=m+1;
for(int j=1;j<=num;j++){
n=m=C=0;
for(int i=0;i<26;i++){
bool f=false,g=false;
for(int k=1;k<=j;k++)f|=x[k].second==i+'a';
for(int k=j+1;k<=num;k++)g|=x[k].second==i+'a';
C|=(f&&g)<<i;
}
X=C;
C|=1<<(x[j].second-'a');T[++m]=x[j].second;
for(int i=x[j].first+1;i<x[j+1].first;i++)T[++m]=t[i];T[m+1]='/0';
for(int i=1;i<=N;i++)if(C>>(s[i]-'a')&1)S[++n]=s[i],lc[n]=i,pre[n]=c[i]+pre[n-1];
for(int i=2,j=0;i<=n;nxt[i++]=(T[j]==T[i]))
while(j&&T[j]!=T[i])j=nxt[j];
for(int i=1,k=0;i<=n;i++){
while(k&&T[k+1]!=S[i])k=nxt[k];
k+=T[k+1]==S[i];
if(k==m)f[lc[i]][j]=max(f[lc[i]][j],f[lc[i-m+1]-1][j-1]+pre[i]-pre[i-m]);//printf("%d %d\n",lc[i-m+1]-1,lc[i]);
}
for(int i=1;i<=N;i++)if(~X>>(s[i]-'a')&1)f[i][j]=max(f[i][j],f[i-1][j]);//printf("%d -> %d\n",i-1,i);puts("-=-=-=-=-=-=-=-=-=-");
}
if(f[N][num]<0)return puts("You better start from scratch man..."),0;
f[N][num]=-f[N][num];
for(int i=1;i<=N;i++)f[N][num]+=c[i];
printf("%lld\n",f[N][num]);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4ms
memory: 100252kb
input:
ababccb abc 7 2 2 4 3 2 1
output:
7
result:
ok single line: '7'
Test #2:
score: 0
Accepted
time: 3ms
memory: 101984kb
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: 20ms
memory: 103500kb
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: 46ms
memory: 103364kb
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: 109ms
memory: 103500kb
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: 28ms
memory: 103560kb
input:
bbaaaabbbbbabaababbaaabbbabaaaababaababaabababbbbabbbbababaabaaabbabaaaabbbabbaababababbabbbabbaababaaaaaabbabbbababbaabbbabbbabbbabaababaaaaaabaaababbbbbbaabaabaaaaaaabbbaaabaabbbababbbbbabbababaababaabbababbaababbbbbbbbbbbaabbbbbabaaabaabaaabaaaaabaaaabbbbbbbaaaabaabbbababbaaaabbabababbbabbbbabbab...
output:
0
result:
ok single line: '0'
Test #7:
score: 0
Accepted
time: 63ms
memory: 103472kb
input:
hdhlkjabgckjkagfgkigfebfjmdabahajicgkfmblafmfgkiimkjlciiaegbkbkicgklhbhfmclghkleghmckbjliiicmmecldieghfdeghgechcjahdfebkhdigbkklcclieccijaemchbmfcggcjmgbdjhcbacleajjjledkfdjebgdmgahkjigjjighlbedbellabffeeckfbghcblmmgjijdehmcameeledejfijfmfcfkjdjklfldhmkabblcbgebhibkmihelehjccgggjhhbjehfidfmmjdgmmjbf...
output:
0
result:
ok single line: '0'
Test #8:
score: 0
Accepted
time: 103ms
memory: 103632kb
input:
soibsuydrizsuvymezuyrewmgwpnzxgyggpzjkdzooisgzbkfqjzkfcklluotqpwganvksoqtzixkfkrtqobdnregwgkxjwzsruvhztscxjyqlhfytomzhxiglxemdhkjnskrsqngojffogrkbygmdgzfwrlhwhhngqpjpepqgynsdybhpuaqhgjroijqofiwnxgxdmhofwsjnmwitruiesefzmabcfsyzrrruidewjowfkwwwqhztsmmtdnejlqhkmbpmknlxijnmzbtqviburbqwufipqsrqplcelovsxz...
output:
0
result:
ok single line: '0'
Test #9:
score: 0
Accepted
time: 0ms
memory: 102240kb
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: 0ms
memory: 100212kb
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: -100
Wrong Answer
time: 4ms
memory: 100272kb
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:
21666314710
result:
wrong answer 1st lines differ - expected: '21140461276', found: '21666314710'