QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#640938 | #6366. Message | lgvc | WA | 0ms | 6204kb | C++14 | 998b | 2024-10-14 17:03:22 | 2024-10-14 17:03:22 |
Judging History
answer
#include <bits/stdc++.h>
#define INF_LL (0x3f3f3f3f3f3f3f3f)
char s[200009],t[200009];
int N,M,v1[30],v2[30],a[200009];
long long su,dp[200009];
signed main(void) {
scanf("%s",s+1);
scanf("%s",t+1);
N=strlen(s+1);M=strlen(t+1);
for(int i=1;i<=M;i++) v1[t[i]-'a']++;
memset(dp,-0x3f,sizeof(dp));
for(int i=1;i<=N;i++) scanf("%d",&a[i]),su+=a[i];
for(int i=1;i<=N;i++) {
if(s[i]==t[1]) {
dp[i]=a[i];
}
}
int id=1;
for(int i=1;i<M;i++) {
v1[t[i]-'a']--;
v2[t[i]-'a']++;
int as=0;
for(int j=0;j<26;j++) {
if(v1[j]&&v2[j]) as|=(1<<j);
}
long long ma=-INF_LL;
while(dp[id]<0&&id<=N) id++;
#pragma GCC unroll 50
for(int j=id;j<=N-(M-i)+1;j++) {
long long tq=ma+a[j];
if((as>>s[j]-'a')&1) ma=-INF_LL;
ma=std::max(ma,dp[j]);
if(t[i+1]==s[j]) dp[j]=tq;else dp[j]=-INF_LL;
}
}
long long as=-INF_LL;
for(int i=M;i<=N;i++) as=std::max(as,dp[i]);
if(as<0) {
printf("-1");
} else {
printf("%lld",su-as);
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 5452kb
input:
ababccb abc 7 2 2 4 3 2 1
output:
7
result:
ok single line: '7'
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 6204kb
input:
babab baab 2 1 3 2 4
output:
-1
result:
wrong answer 1st lines differ - expected: 'You better start from scratch man...', found: '-1'