QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#332163 | #6366. Message | xcyyyyy | WA | 168ms | 98804kb | C++14 | 2.3kb | 2024-02-19 11:07:54 | 2024-02-19 11:07:54 |
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=0;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]*(v[j][s[i+1]-'a']==n+1);
//printf("%d %d %d\n",i,r,w+c[i+1]*(v[j][s[i+1]-'a']==n+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];
}
//puts("-=-=-=-=-=-=-=-=-=");
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][num]);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4ms
memory: 97640kb
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: 97572kb
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: 35ms
memory: 98760kb
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: 65ms
memory: 98568kb
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: 168ms
memory: 98628kb
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: 33ms
memory: 98804kb
input:
bbaaaabbbbbabaababbaaabbbabaaaababaababaabababbbbabbbbababaabaaabbabaaaabbbabbaababababbabbbabbaababaaaaaabbabbbababbaabbbabbbabbbabaababaaaaaabaaababbbbbbaabaabaaaaaaabbbaaabaabbbababbbbbabbababaababaabbababbaababbbbbbbbbbbaabbbbbabaaabaabaaabaaaaabaaaabbbbbbbaaaabaabbbababbaaaabbabababbbabbbbabbab...
output:
856102062
result:
wrong answer 1st lines differ - expected: '0', found: '856102062'