QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#301413 | #6366. Message | SolitaryDream# | WA | 266ms | 196040kb | C++17 | 4.3kb | 2024-01-09 20:19:39 | 2024-01-09 20:19:39 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=2e5+1e3+7,P=(1ll<<61)-1,bs=131313131;
string s,t;
int w[N],n,m;
int pw[N];
int mul(const int &a,const int &b)
{
return (__int128)a*b%P;
}
int add(const int &a,const int &b)
{
return a+b>=P?a+b-P:a+b;
}
signed vis[26],tot[26];
signed key[53],cnt;
int f[53][N];
signed v[53][N],sz[53];
int hat[N],has[53][N],emp[53];
int geth(int *h,int l,int r)
{
return add(h[r],P-mul(h[l-1],pw[r-l+1]));
}
vector<int> ad[2][N];
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin>>s>>t;
int sum=0;
for(auto x:t)
tot[x-'a']++;
n=s.size();
m=t.size();
if(m>n)
{
cout<<"You better start from scratch man...\n";
return 0;
}
pw[0]=1;
for(int i=1;i<=n;i++)
pw[i]=mul(pw[i-1],bs);
for(int i=1;i<=n;i++)
cin>>w[i],sum+=w[i];
s=' '+s,t=' '+t;
for(int i=1;i<=m;i++)
hat[i]=add(mul(hat[i-1],bs),t[i]);
set<int> sta;
emp[0]=1;
for(int i=1;i<=m;i++)
{
if(!vis[t[i]-'a'])
{
key[++cnt]=i;
sta.insert(t[i]);
for(int j=1;j<=n;j++)
if(sta.count(s[j]))
{
v[cnt][++sz[cnt]]=j;
has[cnt][sz[cnt]]=add(mul(has[cnt][sz[cnt]-1],bs),s[j]);
}
}
vis[t[i]-'a']++;
if(vis[t[i]-'a']==tot[t[i]-'a'])
{
key[++cnt]=-i;
sta.erase(t[i]);
emp[cnt]=!sta.size();
for(int j=1;j<=n;j++)
if(sta.count(s[j]))
{
v[cnt][++sz[cnt]]=j;
has[cnt][sz[cnt]]=add(mul(has[cnt][sz[cnt]-1],bs),s[j]);
}
}
}
for(int i=0;i<=cnt;i++)
for(int j=0;j<=n;j++)
f[i][j]=-1e18;
f[0][0]=0;
int now=1,last=0;
for(int i=0;i<=cnt;i++)
{
swap(now,last);
multiset<int> S;
for(int j=0;j<=n;j++)
{
for(auto x:ad[last][j])
{
if(x>0)
S.insert(x-1);
else
S.erase(S.find(-x-1));
}
ad[last][j].clear();
if(s[j]!=t[abs(key[i])])
continue;
if(S.size())
f[i][j]=max(f[i][j],*S.rbegin());
f[i][j]+=w[j];
if(tot[t[abs(key[i])]-'a']==1&&key[i]<0)
f[i][j]-=w[j];
if(f[i][j]<0)
continue;
if(key[i+1]>0)
{
// sta = i, after j, len =
int len=abs(key[i+1])-abs(key[i])-1;
int k=lower_bound(v[i]+1,v[i]+sz[i]+1,j)-v[i];
k+=len;
int pl,pr;
if(!emp[i])
{
if(k>sz[i])
continue;
if(geth(has[i],k-len+1,k)!=geth(hat,abs(key[i])+1,abs(key[i+1])-1))
continue;
pl=v[i][k]+1;
pr=k+1<=sz[i]?v[i][k+1]-1:n;
}
else
{
pl=j+1;
pr=n;
}
if(pl<=pr)
ad[now][pl].push_back((f[i][j]+1)),ad[now][pr+1].push_back(-(f[i][j]+1));
}
else
{
// sta = i, after j, len =
int len=abs(key[i+1])-abs(key[i]);
int pl,pr;
int k=lower_bound(v[i]+1,v[i]+sz[i]+1,j)-v[i];
k+=len;
if(k>sz[i])
continue;
if(geth(has[i],k-len+1,k)!=geth(hat,abs(key[i])+1,abs(key[i+1])))
continue;
pl=pr=v[i][k];
if(pl<=pr)
ad[now][pl].push_back((f[i][j]+1)),ad[now][pr+1].push_back(-(f[i][j]+1));
}
}
}
int ans=-1e18;
for(int i=1;i<=n;i++)
ans=max(ans,f[cnt][i]);
if(ans<0)
cout<<"You better start from scratch man...\n";
else
cout<<sum-ans<<"\n";
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 32276kb
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: 19288kb
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: 48ms
memory: 33404kb
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: 67484kb
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: 266ms
memory: 196040kb
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: 45ms
memory: 42920kb
input:
bbaaaabbbbbabaababbaaabbbabaaaababaababaabababbbbabbbbababaabaaabbabaaaabbbabbaababababbabbbabbaababaaaaaabbabbbababbaabbbabbbabbbabaababaaaaaabaaababbbbbbaabaabaaaaaaabbbaaabaabbbababbbbbabbababaababaabbababbaababbbbbbbbbbbaabbbbbabaaabaabaaabaaaaabaaaabbbbbbbaaaabaabbbababbaaaabbabababbbabbbbabbab...
output:
You better start from scratch man...
result:
wrong answer 1st lines differ - expected: '0', found: 'You better start from scratch man...'