QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#297233#5474. Incredibly Cute Penguin ChicksdoziccTL 1ms5540kbC++141.1kb2024-01-04 07:46:122024-01-04 07:46:12

Judging History

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

  • [2024-01-04 07:46:12]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:5540kb
  • [2024-01-04 07:46:12]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

long long MOD=998244353;
long long dp[1000010], cnti[1000010], cntc[1000010], cntp[1000010];

bool check(int k, int j)
{
    int c=cntc[k]-cntc[j], i=cnti[k]-cnti[j], p=cntp[k]-cntp[j];
    if(i==c and p>i)return true;
    if(c==p and i>c)return true;
    if(p==i and c>p)return true;
    return false;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    string s; cin>>s;
    int n=s.size();
    for(int i=0; i<n; i++)
    {
        cnti[i]=cnti[max(0, i-1)];
        cntp[i]=cntp[max(0, i-1)];
        cntc[i]=cntc[max(0, i-1)];
        if(s[i]=='I')cnti[i]++;
        if(s[i]=='P')cntp[i]++;
        if(s[i]=='C')cntc[i]++;
    }
    dp[0]=1;
    for(int i=1; i<n; i++)
    {
        for(int j=0; j<i; j++)
        {
            if(check(i, j)){dp[i]+=dp[j];}
        }
        if(cntc[i]==cntp[i] and cnti[i]>cntc[i])dp[i]++;
        if(cntp[i]==cnti[i] and cntc[i]>cntp[i])dp[i]++;
        if(cnti[i]==cntc[i] and cntp[i]>cnti[i])dp[i]++;
        dp[i]%=MOD;
       // cout<<dp[i]<<endl;
    }
    cout<<dp[n-1];
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 5528kb

input:

ICPC

output:

2

result:

ok single line: '2'

Test #2:

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

input:

CCCIIIPPP

output:

69

result:

ok single line: '69'

Test #3:

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

input:

PICCICCIPPI

output:

24

result:

ok single line: '24'

Test #4:

score: -100
Time Limit Exceeded

input:

PCPPCCICPICPCPCPCCPPIPPPIICCCICPICCPPPIPCCCCICCIICPCCICCCPCICIPPIPIPIPPCCPCIPPCCPPCCIPPPIPPCIICIIIPPCIPPICPPICCPIICCCCCCCICPCCPPIPIPICPCIICPCCIPICCCPPCPIIICPCPPPIIIIICCCPCICCPPCPPCICIIIPIPICPCPPPPICPCPIPIIICCICPCIPPICCICPIIPPCCCIICPCPCCICCPICPPPPPPICCCIPCCICICIPICIIICCICPCIPIICPIPIIICCPCCIIPCCCCPIPI...

output:


result: