QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#217095#6366. MessageUstinian26TL 0ms0kbC++141.7kb2023-10-16 14:50:302023-10-16 14:50:30

Judging History

你现在查看的是最新测评结果

  • [2023-10-16 14:50:30]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2023-10-16 14:50:30]
  • 提交

answer

#include<bits/stdc++.h>
#define iI inline int 
#define iV inline void
#define iB inline bool
#define eb emplace_back
#define ll long long
#define FOR(i,s,t) for(int i=(s);i<=(t);++i)
#define ROF(i,s,t) for(int i=(s);i>=(t);--i)
using namespace std;
iI read() {
    int x=0;char c=getchar();
    while(!isdigit(c)) c=getchar();
    while(isdigit(c)) x=x*10+(c^48),c=getchar();
    return x;
}
const int N=2e5+3;
const ll inf=1e18;
int sid,T,n,m,w[N];
bool suc[N][26],pre[N][26];
ll f[N],g[N];
char s[N],t[N];
iV chn(ll &x,ll y) {x=x<y?x:y;}
iV solA() {
    if(n<m) return void(printf("-1\n"));
    FOR(i,1,n) g[i]=g[i-1]+w[i];
    ll res=inf;
    FOR(i,1,n-m) chn(res,g[i]+g[n]-g[i+m]);
    printf("%lld\n",res);
}   
int cnt,mat[N],cur,tmp[N];
iV sol() {
    n=read(),m=read();
    scanf("%s%s",s+1,t+1);
    FOR(i,1,n) w[i]=read();
    if(sid==7) return solA();
    FOR(i,1,m) pre[i][t[i]-'a']=suc[i][t[i]-'a']=1;
    FOR(i,1,m) FOR(j,0,25) pre[i][j]|=pre[i-1][j];
    ROF(i,m,1) FOR(j,0,25) suc[i][j]|=suc[i+1][j];
    FOR(i,1,m) f[i]=inf;f[0]=0;
    mat[cnt=1]=0;
    FOR(i,1,n) {
        int c=s[i]-'a';
        ROF(j,cnt,1) {
            int k=mat[j];
            if(s[i]==t[k+1]&&f[k]<f[k+1]) {
                if(f[k+1]==inf) tmp[++cur]=k+1;
                f[k+1]=f[k];
            }
			if(pre[k][c]&&suc[k+1][c]) {f[k]=inf;continue;}
            f[k]+=w[i],tmp[++cur]=k; 
        }
        FOR(j,1,cur) mat[j]=tmp[cur-j+1];
        cnt=cur,cur=0;
    }
    if(f[m]<inf) printf("%lld\n",f[m]);
    else printf("You better start from scratch man...\n");
    FOR(i,1,m) memset(pre[i],0,26),memset(suc[i],0,26); 
}
int main() {
    sol();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

ababccb
abc
7 2 2 4 3 2 1

output:


result: