QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#641557 | #6366. Message | drowsylve_233 | TL | 1152ms | 234000kb | C++14 | 3.2kb | 2024-10-14 21:11:43 | 2024-10-14 21:11:44 |
Judging History
answer
bool M1;
#include<bits/stdc++.h>
using namespace std;
#define look_memory cerr<<abs(&M2-&M1)/1024.0/1024<<'\n'
#define look_time cerr<<(clock()-ST)*1.0/CLOCKS_PER_SEC<<'\n'
//#define int long long
//#define double long double
#define ll long long
#define db double
#define pb push_back
#define pii pair<int,int>
#define mkp make_pair
#define fr first
#define sc second
template<typename T> void ckmin(T &x,T y){x=min(x,y);}
template<typename T> void ckmax(T &x,T y){x=max(x,y);}
mt19937 rnd(time(0));
const int N=200005;
const ll inf=1e18;
const int mod=1000000007;
int n,m,a[N];
string s,t;
ll sum;
/*int pre1[N][26];
ll f1[1005][1005];
void solve1(){
for(int i=1;i<=m;i++){
for(int j=0;j<26;j++) pre1[i][j]=pre1[i-1][j];
pre1[i][t[i]-'a']++;
}
for(int i=0;i<=n;i++) for(int j=1;j<=m;j++) f1[i][j]=-inf;
f1[0][0]=0;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(s[i]==t[j]) ckmax(f1[i][j],f1[i-1][j-1]+a[i]);
if(pre1[j][s[i]-'a']==0 || pre1[j][s[i]-'a']==pre1[m][s[i]-'a']) ckmax(f1[i][j],f1[i-1][j]);
}
}
ll ans=-inf;
for(int i=1;i<=n;i++) ckmax(ans,f1[i][m]);
if(ans<0) cout<<"-1";
else cout<<sum-ans;
}*/
int tl[26],tr[26],cut[55],tot;
bool at[26],vis[26];
ll pre[N];
int pos[N];
bool pk[N][55];
int nxt[N];
int g[N][55];
ll val[N][55],f[N][55];
string s0,t0;
void calc(int p){
for(int i=0;i<26;i++){
if(tl[i]<=cut[p] && tr[i]>=cut[p]){
at[i]=1;
vis[i]=(tl[i]==cut[p]);
}else{
at[i]=vis[i]=0;
}
}
int n0=0;s0=" ";
for(int i=1;i<=n;i++){
if(!at[s[i]-'a']) continue;//del
s0=s0+s[i];
pos[++n0]=i;
pre[n0]=pre[n0-1]+a[i];
if(vis[s[i]-'a']) pk[i][p]=1;
}
int m0=cut[p+1]-cut[p];t0=" ";
for(int i=cut[p];i<cut[p+1];i++) t0=t0+t[i];
for(int i=0;i<=m0;i++) nxt[i]=0;
for(int i=2,j=0;i<=m0;i++){
while(j&&t0[j+1]!=t0[i]) j=nxt[j];
if(t0[j+1]==t0[i]) j++;
nxt[i]=j;
}
for(int i=1;i<=n0;i++) g[pos[i]][p]=-1;
for(int i=1,j=0;i<=n0;i++){
while(j&&t0[j+1]!=s0[i]) j=nxt[j];
if(t0[j+1]==s0[i]) j++;
if(j==m0){
g[pos[i-j+1]][p]=pos[i];
val[pos[i-j+1]][p]=pre[i]-pre[i-j];
j=nxt[j];
}
}
}
bool M2;
signed main(){
// freopen("B8.in","r",stdin);
// freopen("B8.out","w",stdout);
// look_memory;
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>s>>t;
n=s.size(),m=t.size();
s=" "+s;t=" "+t;
for(int i=1;i<=n;i++) cin>>a[i],sum+=a[i];
if(m>n){cout<<"You better start from scratch man...";return 0;}
// if(n<=1000){solve1();return 0;}
for(int i=0;i<26;i++) tl[i]=m+1,tr[i]=0;
for(int i=1;i<=m;i++) ckmin(tl[t[i]-'a'],i),ckmax(tr[t[i]-'a'],i);
cut[++tot]=1;
cut[++tot]=m+1;
for(int i=0;i<26;i++){
if(tl[i]==m+1) continue;
cut[++tot]=tl[i];
cut[++tot]=tr[i]+1;
}
sort(cut+1,cut+1+tot);
tot=unique(cut+1,cut+1+tot)-cut-1;
for(int i=1;i<tot;i++) calc(i);
for(int i=1;i<=n+1;i++) for(int j=1;j<=tot;j++) f[i][j]=-inf;
f[1][1]=0;
for(int i=1;i<=n;i++){
for(int j=1;j<tot;j++){
if(f[i][j]==-inf) continue;
if(g[i][j]==0||pk[i][j]) ckmax(f[i+1][j],f[i][j]);
if(g[i][j]>0) ckmax(f[g[i][j]+1][j+1],f[i][j]+val[i][j]);
}
}
ll ans=-inf;
for(int i=1;i<=n+1;i++) ckmax(ans,f[i][tot]);
if(ans<0) cout<<"You better start from scratch man...";//cout<<"-1";
else cout<<sum-ans;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 3ms
memory: 15960kb
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: 13856kb
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: 1152ms
memory: 234000kb
input:
bbaaaabbbbbabaababbaaabbbabaaaababaababaabababbbbabbbbababaabaaabbabaaaabbbabbaababababbabbbabbaababaaaaaabbabbbababbaabbbabbbabbbabaababaaaaaabaaababbbbbbaabaabaaaaaaabbbaaabaabbbababbbbbabbababaababaabbababbaababbbbbbbbbbbaabbbbbabaaabaabaaabaaaaabaaaabbbbbbbaaaabaabbbababbaaaabbabababbbabbbbabbab...
output:
You better start from scratch man...
result:
ok single line: 'You better start from scratch man...'
Test #4:
score: -100
Time Limit Exceeded
input:
bdabcfbdfcffebebcabbadacbbaeeaffbdedeedfabefdfdbddcecdaaddafdfbbdceccedebcecdfbcfbaafcefeecffdabfaacbeeecfeffaaafaefdcdaaeaeecfafcdadbfbccbdecacfeabdbfcacafebdcfbfbebacbffaecbfbcedccabbdecabaebbbdbcfbaeadfcadfadfaebaddbebfcbefdabdcefbbdaaaabcefedabcabcafedcfadedfdcbbccbffdcfdfcfcdfcfbbdabdbbeecafecc...