QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#332160 | #6366. Message | xcyyyyy | RE | 152ms | 98736kb | C++14 | 2.3kb | 2024-02-19 11:06:46 | 2024-02-19 11:06:47 |
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][m]);
}
详细
Test #1:
score: 100
Accepted
time: 3ms
memory: 98588kb
input:
ababccb abc 7 2 2 4 3 2 1
output:
7
result:
ok single line: '7'
Test #2:
score: 0
Accepted
time: 7ms
memory: 97864kb
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: 31ms
memory: 98612kb
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: 58ms
memory: 98736kb
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: 152ms
memory: 98736kb
input:
soibsuydrizsuvymezuyrewmgwpnzxgyggpzjkdzooisgzbkfqjzkfcklluotqpwganvksoqtzixkfkrtqobdnregwgkxjwzsruvhztscxjyqlhfytomzhxiglxemdhkjnskrsqngojffogrkbygmdgzfwrlhwhhngqpjpepqgynsdybhpuaqhgjroijqofiwnxgxdmhofwsjnmwitruiesefzmabcfsyzrrruidewjowfkwwwqhztsmmtdnejlqhkmbpmknlxijnmzbtqviburbqwufipqsrqplcelovsxz...
output:
You better start from scratch man...
result:
ok single line: 'You better start from scratch man...'
Test #6:
score: -100
Runtime Error
input:
bbaaaabbbbbabaababbaaabbbabaaaababaababaabababbbbabbbbababaabaaabbabaaaabbbabbaababababbabbbabbaababaaaaaabbabbbababbaabbbabbbabbbabaababaaaaaabaaababbbbbbaabaabaaaaaaabbbaaabaabbbababbbbbabbababaababaabbababbaababbbbbbbbbbbaabbbbbabaaabaabaaabaaaaabaaaabbbbbbbaaaabaabbbababbaaaabbabababbbabbbbabbab...