QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#331670#6366. MessagekkioWA 57ms92196kbC++209.5kb2024-02-18 16:51:452024-02-18 16:51:46

Judging History

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

  • [2024-02-18 16:51:46]
  • 评测
  • 测评结果:WA
  • 用时:57ms
  • 内存:92196kb
  • [2024-02-18 16:51:45]
  • 提交

answer

#include <bits/stdc++.h>
//#define Kachang 1
#ifdef Kachang
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2")
#pragma GCC optimize("Ofast","unroll-loops","inline","no-stack-protector")
#else
#pragma GCC optmize("2")
#endif
using namespace std;
namespace Def{
    #define fir first
    #define sec second
    #define lson(i) (tr[i].ls)
    #define rson(i) (tr[i].rs)
    #define FIO(file) freopen(file".in","r",stdin), freopen(file".out","w",stdout)
    #define Untie() ios::sync_with_stdio(0), cin.tie(0),cout.tie(0)
    typedef long long ll;
    typedef double db;
    typedef long double ldb;
    typedef unsigned int uint;
    typedef unsigned long long ull;
    typedef pair<int,int> pii;
    typedef pair<ll,ll> pll;
    typedef __int128_t i128;
    typedef __uint128_t u128;
}
using namespace Def;
namespace FastIO {
    struct IO {
        char ibuf[(1 << 20) + 1], *iS, *iT, obuf[(1 << 20) + 1], *oS;
        IO() : iS(ibuf), iT(ibuf), oS(obuf) {} ~IO() { fwrite(obuf, 1, oS - obuf, stdout); }
        #if ONLINE_JUDGE
        #define gh() (iS == iT ? iT = (iS = ibuf) + fread(ibuf, 1, (1 << 20) + 1, stdin), (iS == iT ? EOF : *iS++) : *iS++)
        #else
        #define gh() getchar()
        #endif
        inline bool eof (const char &ch) { return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t' || ch == EOF; }
        inline long long read() {
            char ch = gh();
            long long x = 0;
            bool t = 0;
            while (ch < '0' || ch > '9') t |= ch == '-', ch = gh();
            while (ch >= '0' && ch <= '9') x = (x << 1) + (x << 3) + (ch ^ 48), ch = gh();
            return t ? ~(x - 1) : x;
        }
        inline void read (char *s) {
            char ch = gh(); int l = 0;
            while (eof(ch)) ch = gh();
            while (!eof(ch)) s[l++] = ch, ch = gh();
            s[l] = 0;
        }
        inline void read (double &x) {
            char ch = gh(); bool t = 0;
            while (ch < '0' || ch > '9') t |= ch == '-', ch = gh();
            while (ch >= '0' && ch <= '9') x = x * 10 + (ch ^ 48), ch = gh();
            if (ch != '.') return t && (x = -x), void(); ch = gh();
            for (double cf = 0.1; '0' <= ch && ch <= '9'; ch = gh(), cf *= 0.1) x += cf * (ch ^ 48);
            t && (x = -x);
        }
        inline void pc (char ch) {
            #ifdef ONLINE_JUDGE
            if (oS == obuf + (1 << 20) + 1) fwrite(obuf, 1, oS - obuf, stdout), oS = obuf; 
            *oS++ = ch;
            #else
            putchar(ch);
            #endif
        }
        inline void write (char *s)
        {
            int len = strlen(s);
            for(int i = 0; i < len; i++)pc(s[i]);
        }
        template<typename _Tp>
        inline void write (_Tp x) {
            static char stk[64], *tp = stk;
            if (x < 0) x = ~(x - 1), pc('-');
            do *tp++ = x % 10, x /= 10;
            while (x);
            while (tp != stk) pc((*--tp) | 48);
        }
        inline void puts(const char *s){
            int len = strlen(s);
            for (int i = 0; i < len; i++)pc(s[i]);
        }
    } io;
    inline long long read () { return io.read(); }
    template<typename Tp>
    inline void read (Tp &x) { io.read(x); }
    template<typename _Tp>
    inline void write (_Tp x) { io.write(x); }
}
using namespace FastIO;
namespace misc{
    constexpr int infi=1e9;
    constexpr int minfi=0x3f3f3f3f;
    constexpr ll infl=1e18;
    constexpr ll minfl=0x3f3f3f3f3f3f3f3f;
    constexpr int MOD=998244353;
    constexpr int inv2=(MOD+1)/2;
    constexpr int inv3=(MOD+1)/3;
    constexpr double eps=1e-6;
    mt19937_64 rnd(0x3408532);
    template<typename T,typename E>
        inline T ksm(T b,E p){T ret=1;while(p){if(p&1)ret=1ll*ret*b%MOD;b=1ll*b*b%MOD;p>>=1;}return ret;}
    template<typename T,typename E,typename R>
        inline T ksm(T b,E p,R mod){T ret=1;while(p){if(p&1)ret=1ll*ret*b%mod;b=1ll*b*b%mod;p>>=1;}return ret;}
    template<typename T> 
        inline T ginv(T v){return ksm(v,MOD-2);}
    template<typename T,typename E>
        inline void cmax(T &a,E b){a<b?(a=b,1):0;}
    template<typename T,typename E>
        inline void cmin(T &a,E b){a>b?(a=b,1):0;}
    template<typename T,typename E>
        inline void cadd(T &a,E b){(a+=b)>=MOD?(a-=MOD):0;}
    template<typename T,typename E>
        inline void csub(T &a,E b){(a-=b)<0?(a+=MOD):0;}
    template<typename T,typename E>
        inline void cmul(T &a,E b){a=(ll)a*b%MOD;}
    template<typename T,typename E>
        inline T madd(T a,E b){return (a+=b)>=MOD?(a-MOD):a;}
    template<typename T,typename E>
        inline T msub(T a,E b){return (a-=b)<0?(a+MOD):a;}
    template<typename T,typename E>
        inline T mmul(T a,E b){return (ll)a*b%MOD;}
    template<typename T>
        struct dseg{T *first,*last;dseg(T* _l,T* _r):first(_l),last(_r){}};
    inline void debug(void){cerr<<'\n';}
    template<typename T,typename... arg>
        inline void debug(dseg<T> A,arg... v){cerr<<"[ ";for(T* i=A.first;i!=A.last;++i)cerr<<*i<<' ';cerr<<"] ";debug(v...);}
    template<typename T,typename... arg>
        inline void debug(T x,arg... r){cerr<<x<<' ';debug(r...);}
    template<typename T>
        inline T randseg(T l,T r){assert(l<=r);return rnd()%(r-l+1)+l;}
    template<typename T>
        inline bool gbit(T v,int bit){return v>>bit&1;}
    template<typename T> 
        inline void FWTXor(T *a,int n){for(int i=2;i<=n;i<<=1)for(int p=i>>1,j=0;j<n;j+=i)for(int k=j;k<j+p;k++){T x=a[k],y=a[k+p];a[k]=madd(x,y),a[k+p]=msub(x,y);}}
    template<typename T> 
        inline void iFWTXor(T *a,int n){for(int i=2;i<=n;i<<=1)for(int p=i>>1,j=0;j<n;j+=i)for(int k=j;k<j+p;k++){T x=a[k],y=a[k+p];a[k]=mmul(madd(x,y),inv2),a[k+p]=mmul(msub(x,y),inv2);}}
    int timest=0;
    inline void record(){timest=clock()*1000/CLOCKS_PER_SEC;}
    inline int timegap(){int nowtime=clock()*1000/CLOCKS_PER_SEC;return nowtime-timest;}
    inline ll gcd(ll a,ll b){if(!b||!a) return a+b;ll az=__builtin_ctz(a),bz=__builtin_ctz(b),z=(az>bz)?bz:az,t;b>>=bz;while(a) a>>=az,t=a-b,az=__builtin_ctz(t),b=a<b?a:b,a=t<0?-t:t;return b<<z;}
    inline ll exgcd(ll a,ll b,ll &x,ll &y){if(!b){x=1,y=0;return a;}ll g=exgcd(b,a%b,y,x);y-=x*(a/b);return g;}
    inline ll Sum1(ll n){return n*(n+1)/2;}
    inline ll Sum2(ll n){return n*(n+1)*(2*n+1)/6;}
    inline ll Sqr(ll n){return n*n;}
    #define binom(n,m) ((n)<0||(m)<0||(n)<(m)?0:1ll*fac[(n)]*ifac[(m)]%mod*ifac[(n)-(m)]%mod)
    #define likely(x) (__builtin_expect(!!(x),1))
    #define unlikely(x) (__builtin_expect(!!(x),0))
}
using namespace misc;
namespace Barret
{
    class reduction
    {
    private:
        __uint128_t brt;
        int mod;
    public:
        reduction(){};
        reduction(int __mod):brt(((__uint128_t)1<<64)/__mod),mod(__mod){}
        inline void setmod(int __mod){brt=((__uint128_t)1<<64)/__mod,mod=__mod;}
        template<typename T> inline void fix(T& val){val-=mod*(brt*val>>64);while(val>=mod)val-=mod;}
        template<typename T> inline int fixv(T val){val-=mod*(brt*val>>64);return val>=mod?val-mod:val;}
    };
}
using namespace Barret;
const int maxn=2e5+10,sig=60;
char s[maxn],t[maxn],ts[maxn],sz[maxn];
int c[maxn],n,m,len,nl,C[sig],L[sig],R[sig],tot,Lt[sig],Rt[sig],nxt[maxn],tpos[maxn];
int sv[maxn];
ll dp[sig][maxn],Sum;
struct node{
    int pos,ty,s;
};
bool cmp(node a,node b){return a.pos==b.pos?a.ty<b.ty:a.pos<b.pos;}
vector< node > rps;
int main()
{
    scanf("%s%s",s+1,t+1);
    n=strlen(s+1),m=strlen(t+1);
    for(int i=1;i<=n;i++)scanf("%d",&c[i]),Sum+=c[i];
    for(int i=1;i<=m;i++)
        if(!L[t[i]-'a'])L[t[i]-'a']=i;
    for(int i=m;i>=1;i--)
        if(!R[t[i]-'a'])R[t[i]-'a']=i;
    for(int i=0;i<26;i++)
        if(L[i])rps.push_back({L[i],0,i}),rps.push_back({R[i],1,i});
    sort(rps.begin(),rps.end(),cmp);
    int S=0,lst=-1;
    for(int i=0;i<rps.size();i++)
    {
        if(rps[i].ty==0)
        {
            if(lst!=-1&&lst<rps[i].pos)++tot,Lt[tot]=lst,Rt[tot]=rps[i].pos-1,C[tot]=S;
            lst=rps[i].pos;
            S^=(1<<rps[i].s);
        }
        else 
        {
            if(lst<=rps[i].pos)++tot,Lt[tot]=lst,Rt[tot]=rps[i].pos,C[tot]=S;
            lst=rps[i].pos+1;
            S^=(1<<rps[i].s);
        }
    }
    //for(int i=1;i<=tot;i++)
    //    cout<<Lt[i]<<' '<<Rt[i]<<'\n';
    for(int i=0;i<=n;i++)dp[0][i]=0;
    for(int nt=1;nt<=tot;nt++)
    {
      //  cout<<"!"<<nt<<'\n';
        len=nl=0;
        for(int j=1;j<=n;j++)if(C[nt]>>(s[j]-'a')&1)++len,sv[len]=c[j],ts[len]=s[j],tpos[len]=j;
        for(int i=1;i<=n;i++)sv[i]+=sv[i-1];
        for(int j=Lt[nt];j<=Rt[nt];j++)sz[++nl]=t[j];sz[nl+1]=0;
        for(int i=0;i<=n;i++)dp[nt][i]=-infl;
        nxt[1]=0;
        for(int i=2,j=0;i<=nl;i++)
        {
            while(j&&sz[j+1]!=sz[i])j=nxt[j];
            if(sz[j+1]==sz[i])j++;
            nxt[i]=j;
        }
        for(int i=1,j=0;i<=len;i++)
        {
            while(j&&sz[j+1]!=ts[i])j=nxt[j];
            if(sz[j+1]==ts[i])j++;
            if(j==nl)
            {
                int rp=tpos[i],lp=tpos[i-nl+1];
                //cout<<rp<<' '<<lp<<'\n';
                dp[nt][rp]=max(dp[nt][rp],dp[nt-1][lp-1]+sv[i]-sv[i-nl]);
            }
        }
        for(int i=1;i<=n;i++)dp[nt][i]=max(dp[nt][i],dp[nt][i-1]);
       // for(int i=0;i<=n;i++)cout<<dp[nt][i]<<' ';cout<<'\n';
    }
    if(dp[tot][n]<0)cout<<"You better start from scratch man...\n";
    else cout<<Sum-dp[tot][n]<<'\n';
}

詳細信息

Test #1:

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

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

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: 10ms
memory: 17464kb

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: 29ms
memory: 30700kb

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: 57ms
memory: 92196kb

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: 14ms
memory: 16876kb

input:

bbaaaabbbbbabaababbaaabbbabaaaababaababaabababbbbabbbbababaabaaabbabaaaabbbabbaababababbabbbabbaababaaaaaabbabbbababbaabbbabbbabbbabaababaaaaaabaaababbbbbbaabaabaaaaaaabbbaaabaabbbababbbbbabbababaababaabbababbaababbbbbbbbbbbaabbbbbabaaabaabaaabaaaaabaaaabbbbbbbaaaabaabbbababbaaaabbabababbbabbbbabbab...

output:

You better start from scratch man...

result:

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