QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#301427#6366. MessageSolitaryDream#WA 39ms37472kbC++174.7kb2024-01-09 20:56:432024-01-09 20:56:44

Judging History

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

  • [2024-01-09 20:56:44]
  • 评测
  • 测评结果:WA
  • 用时:39ms
  • 内存:37472kb
  • [2024-01-09 20:56:43]
  • 提交

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[2][N];

signed v[53][N],sz[53];

int sw[53][N];

int hat[N],has[53][N],emp[53];

int geth(int *h,int l,int r)
{
    if(l>r)
        return 0;
    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;
                    sw[cnt][sz[cnt]]=sw[cnt][sz[cnt]-1]+w[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;
                    sw[cnt][sz[cnt]]=sw[cnt][sz[cnt]-1]+w[j];
                    has[cnt][sz[cnt]]=add(mul(has[cnt][sz[cnt]-1],bs),s[j]);
                }
        }
    }



    for(int i=0;i<=1;i++)
        for(int j=0;j<=n;j++)
            f[i][j]=-2e18;
    f[0][0]=0;

    int now=0,last=1;

    for(int i=0;i<=cnt;i++)
    {
        swap(now,last);
        for(int j=0;j<=cnt;j++)
            f[now][j]=-2e18;
        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[last][j]=max(f[last][j],*S.rbegin());
            f[last][j]+=w[j];
            if(tot[t[abs(key[i])]-'a']==1&&key[i]<0)
                f[last][j]-=w[j];
            if(f[last][j]<0||i==cnt)
                continue;
            if(key[i+1]>0)
            {
                // sta = i, after j, len = 
                int len=abs(key[i+1])-abs(key[i])-1;

                int k=upper_bound(v[i]+1,v[i]+sz[i]+1,j)-v[i];
                k+=len-1;

                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=max(v[i][k]+1ll,j+1);
                    pr=k+1<=sz[i]?v[i][k+1]-1:n;
                }
                else
                {
                    pl=j+1;
                    pr=n;
                }
                int val=f[last][j]+(len==0?0:sw[i][k]-sw[i][k-len]);
                if(pl<=pr)
                    ad[now][pl].push_back((val+1)),ad[now][pr+1].push_back(-(val+1));
            }
            else
            {

                // sta = i, after j, len = 
                int len=abs(key[i+1])-abs(key[i]);
                int pl,pr;
                int k=upper_bound(v[i]+1,v[i]+sz[i]+1,j)-v[i];
                k+=len-1;

                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];
                
                int val=f[last][j]+(len==0?0:sw[i][k-1]-sw[i][k-len]);
                if(pl<=pr)
                    ad[now][pl].push_back((val+1)),ad[now][pr+1].push_back(-(val+1));
            }
        }
    }
    int ans=-2e18;
    for(int i=1;i<=n;i++)
        ans=max(ans,f[last][i]);
    if(ans<0)
        cout<<"You better start from scratch man...\n";
    else
        cout<<sum-ans<<"\n";
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 26088kb

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: 21628kb

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: -100
Wrong Answer
time: 39ms
memory: 37472kb

input:

bbaaaabbbbbabaababbaaabbbabaaaababaababaabababbbbabbbbababaabaaabbabaaaabbbabbaababababbabbbabbaababaaaaaabbabbbababbaabbbabbbabbbabaababaaaaaabaaababbbbbbaabaabaaaaaaabbbaaabaabbbababbbbbabbababaababaabbababbaababbbbbbbbbbbaabbbbbabaaabaabaaabaaaaabaaaabbbbbbbaaaabaabbbababbaaaabbabababbbabbbbabbab...

output:

99810271267485

result:

wrong answer 1st lines differ - expected: 'You better start from scratch man...', found: '99810271267485'