QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#332151 | #6366. Message | xcyyyyy | WA | 200ms | 98764kb | C++14 | 2.2kb | 2024-02-19 10:45:18 | 2024-02-19 10:45:20 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define N 200005
int n,m,c[N];
char s[N],t[N];
int num;
int vis[200];
pair<int,int> x[60];char a[60];
int v[60][26],b[60][26];
ll f[N][60],cnt[60];
vector<int> G;
int main(){
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;
x[num+1].first=m+1;
//printf("%d\n",num);
for(int i=1;i<=num;i++){
a[i]=x[i].second;
//printf("%d %c\n",x[i].first,x[i].second);
for(int j=x[i].first+1;j<x[i+1].first;j++)
++v[i][t[j]-'a'];
for(int j=0;j<26;j++){
bool f=false,g=false;
for(int k=1;k<=i;k++)f|=x[k].second==j+'a';
for(int k=i+1;k<=num;k++)g|=x[k].second==j+'a';
if(!f||!g)v[i][j]=n+1;
//printf("%d ",v[i][j]);
}
//puts("");
}
memset(f,-0x3f,sizeof(f));
for(int i=0;i<=n;i++)f[i][0]=0;
for(int j=1;j<=num;j++){//转移第 j 段
memset(cnt,0,sizeof(cnt));int gd=0,all=0;ll w=0;
for(int i=0;i<26;i++)gd+=v[j][i]==0,all+=v[j][i]!=n+1;
for(int i=0,r=1;i<n;i++){
while(r<n&&(gd!=all&&cnt[s[r+1]-'a']+1<=v[j][s[r+1]-'a']||r<i+1)){
++r;
++cnt[s[r]-'a'];
w+=(v[j][s[r]-'a']!=n+1)*c[r];
gd+=v[j][s[r]-'a']!=n+1&&cnt[s[r]-'a']==v[j][s[r]-'a'];
}
if(s[i+1]==a[j]&&gd==all)f[r][j]=f[i][j-1]+w+c[i+1];
gd-=v[j][s[i+1]-'a']!=n+1&&cnt[s[i+1]-'a']==v[j][s[i+1]-'a'];
--cnt[s[i+1]-'a'];
w-=(v[j][s[i+1]-'a']!=n+1)*c[i+1];
}
for(int i=1;i<=n;i++)if(v[j][s[i]-'a']==n+1)f[i][j]=max(f[i][j],f[i-1][j]);
}
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][m]);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 8ms
memory: 97572kb
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: 97520kb
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: 34ms
memory: 98600kb
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: 70ms
memory: 98564kb
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: 200ms
memory: 98764kb
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: 35ms
memory: 98564kb
input:
bbaaaabbbbbabaababbaaabbbabaaaababaababaabababbbbabbbbababaabaaabbabaaaabbbabbaababababbabbbabbaababaaaaaabbabbbababbaabbbabbbabbbabaababaaaaaabaaababbbbbbaabaabaaaaaaabbbaaabaabbbababbbbbabbababaababaabbababbaababbbbbbbbbbbaabbbbbabaaabaabaaabaaaaabaaaabbbbbbbaaaabaabbbababbaaaabbabababbbabbbbabbab...
output:
You better start from scratch man...
result:
wrong answer 1st lines differ - expected: '0', found: 'You better start from scratch man...'