QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#181337#5474. Incredibly Cute Penguin ChicksSolitaryDream#RE 565ms33440kbC++201.6kb2023-09-16 17:51:532023-09-16 17:51:53

Judging History

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

  • [2023-09-16 17:51:53]
  • 评测
  • 测评结果:RE
  • 用时:565ms
  • 内存:33440kb
  • [2023-09-16 17:51:53]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

const int N=2e6+1e3+7,P=998244353,S=1e6,L=2e6;

int n,c[3];

char s[N];

struct Seg{
    int rt[N],tot;

    struct ND{
        int ls,rs;
        int s;
    }t[N*2+1];

    void ins(int &x,int l,int r,int p,int v)
    {
        if(!x)
            x=++tot;
        t[x].s=(t[x].s+v)%P;
        if(l==r)
            return;
        int mid=(l+r)>>1;
        if(p<=mid)
            ins(t[x].ls,l,mid,p,v);
        else
            ins(t[x].rs,mid+1,r,p,v);
    }

    int qry(int x,int l,int r,int L,int R)
    {
        if(L>R)
            return 0;
        if(!x)
            return 0;
        if(L<=l&&r<=R)
            return t[x].s;
        int mid=(l+r)>>1;
        int ret=0;
        if(L<=mid)
            ret=(ret+qry(t[x].ls,l,mid,L,R))%P;
        if(R>mid)
            ret=(ret+qry(t[x].rs,mid+1,r,L,R))%P;
        return ret;
    }
}T[3];

int f[N];

int main()
{
    scanf("%s",s+1);
    n=strlen(s+1);
    f[0]=1;
    T[0].ins(T[0].rt[0+S],0,L,S,1);
    T[1].ins(T[1].rt[0+S],0,L,S,1);
    T[2].ins(T[2].rt[0+S],0,L,S,1);
    for(int i=1;i<=n;i++)
    {
        int x=(s[i]=='I'?0:(s[i]=='C'?1:2));
        c[x]++;
        for(int j=0;j<3;j++)
        {
            int A=c[j],B=c[(j+1)%3],C=c[(j+2)%3];
            f[i]=(f[i]+T[j].qry(T[j].rt[A-B+S],0,L,0,C-A+S-1))%P;
        }
        for(int j=0;j<3;j++)
        {
            int A=c[j],B=c[(j+1)%3],C=c[(j+2)%3];
            T[j].ins(T[j].rt[A-B+S],0,L,C-A+S,f[i]);
        }
    }
    printf("%d\n",f[n]);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5980kb

input:

ICPC

output:

2

result:

ok single line: '2'

Test #2:

score: 0
Accepted
time: 1ms
memory: 5900kb

input:

CCCIIIPPP

output:

69

result:

ok single line: '69'

Test #3:

score: 0
Accepted
time: 1ms
memory: 5980kb

input:

PICCICCIPPI

output:

24

result:

ok single line: '24'

Test #4:

score: 0
Accepted
time: 565ms
memory: 30688kb

input:

PCPPCCICPICPCPCPCCPPIPPPIICCCICPICCPPPIPCCCCICCIICPCCICCCPCICIPPIPIPIPPCCPCIPPCCPPCCIPPPIPPCIICIIIPPCIPPICPPICCPIICCCCCCCICPCCPPIPIPICPCIICPCCIPICCCPPCPIIICPCPPPIIIIICCCPCICCPPCPPCICIIIPIPICPCPPPPICPCPIPIIICCICPCIPPICCICPIIPPCCCIICPCPCCICCPICPPPPPPICCCIPCCICICIPICIIICCICPCIPIICPIPIIICCPCCIIPCCCCPIPI...

output:

216523282

result:

ok single line: '216523282'

Test #5:

score: 0
Accepted
time: 552ms
memory: 29796kb

input:

ICIPCICCIPIPIIPPCPCICICPCPCPIIICICPPICCICPIPCPCIIPPIPCCIPIPIPIICCICICCCIPPIIPCPPCIIICCICCCCCCPIPICCIPIICIICPIPCCICPPCCIPIPIICCCPCCIPCPPCCIIIIIPCIPIIPICIIIPIICCCIPPPIPICIIIICIIIPICIICPIPCCICIPCCIPICCCPPIPIIPICPPCPICIPIPPPPPCIPCCIPPICIPCICPCCCCPPIIIPCPICCICIPIIPICPIIIIPPPCPIIIPCCPPIIPPICPIIICCCPICPPIC...

output:

977504498

result:

ok single line: '977504498'

Test #6:

score: 0
Accepted
time: 538ms
memory: 33440kb

input:

PPCCCICCIPPICCPCCCCIPPPIICPIPIPPPPIPPPPPPCPIPICCPCCPICPIPPPIIPIPIIPPCCPIICPPIIIPPCCCIIPCCIPCCCCCCIIIPIPCICCIICIIICCCCPCCICPPCCPCCIPICCPPIIPIIPIPCIIPIIPPPCCIPCPCCICCIPICPPPCIPPIPCCPCPCCIPIICCIPCCIPPCPCIPICIICPPICIIICIPIIIIIPCCCPPIPPPCIICIIIPPCIPCIPCIICCCCPIPCPICICPIPCPPIPIPICCPCCCCPCIPCPPCCIPCCCCCPII...

output:

785880133

result:

ok single line: '785880133'

Test #7:

score: 0
Accepted
time: 536ms
memory: 27552kb

input:

ICIPCPIPCCCCCCCPCCPCCIPCPCPIPPCPIPCICPPIPPPPICPIIPPIICPICPICPPICICICCCIIPCPPCCICCCCPIICPPPIPIPCICPIPPPPCCPICPCPICICPPIIIICIICPPIPIIICCCCPIPIIPICCCIPCCPPCPPPPIIIIICIPCPCCPIIICICIPPCCPIPPCIIPCCCIIICPCIPCIIIIPCIIPCIICCCIPPIPPCIIPCICIPIIPICCICCPCPIICCCIPIICCCPIPPCCIIIICPPIICPCPCIPPPCPCICPPIPIPCCPIPPPIPI...

output:

687587235

result:

ok single line: '687587235'

Test #8:

score: 0
Accepted
time: 542ms
memory: 31232kb

input:

IICCCIPIIIIIPICIICPCPCIICCIIICCCIIPICICCCPCPCPPPIIPIPPICIICICIPIICCICCIIIPCIICCPPIPICIPPCPCPCPIICCIIICIPPICCICPPIPPPPICPCPIPCCCPCPCPPPPIICPCIIIIIIIPIPIICICCPPIIPPCICPCPCIPCPICPPPICCICIICPPIPPPIPIPIPPCIPPCIPPCPPPIICICCCPICIPPIPCCPIIPPCIPPICCIIIPPPPPIIPPICPCPCIPPCCPCIIIPPICCCIIIIICIPPIIICPCIIICPPCPCPP...

output:

698376687

result:

ok single line: '698376687'

Test #9:

score: 0
Accepted
time: 559ms
memory: 32084kb

input:

IIPICCCCIPPCCPICCIIPPPCIPCCPPIPIICICPCCIIPPCCCICICPPICCICPPIICIIPICPICIPPPPCPCCPIICCPPIPPCIIIIPICICICCIIPPCICCCCCPICPIPCPPCCPPICPICCCICCIPICCICPIICCPIPIPICCPPCCPCPCCPICCPICCCCCCIPIICPIPICICCPIIPIPICIICIPPPIPCICIPIPPICPICICPPICICCIPCIPPPCIPIIPPPIICICPPPIICCCPIIICIPIPPICICIPPPCCPCCIIPCCCPPPCPICPICPPCP...

output:

850857669

result:

ok single line: '850857669'

Test #10:

score: -100
Runtime Error

input:

IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII...

output:


result: