QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#297232#5474. Incredibly Cute Penguin ChicksdoziccTL 1ms5576kbC++141.1kb2024-01-04 07:44:522024-01-04 07:44:54

Judging History

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

  • [2024-01-04 07:44:54]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:5576kb
  • [2024-01-04 07:44:52]
  • 提交

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()
{
    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;
}

详细

Test #1:

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

input:

ICPC

output:

2

result:

ok single line: '2'

Test #2:

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

input:

CCCIIIPPP

output:

69

result:

ok single line: '69'

Test #3:

score: 0
Accepted
time: 0ms
memory: 5536kb

input:

PICCICCIPPI

output:

24

result:

ok single line: '24'

Test #4:

score: -100
Time Limit Exceeded

input:

PCPPCCICPICPCPCPCCPPIPPPIICCCICPICCPPPIPCCCCICCIICPCCICCCPCICIPPIPIPIPPCCPCIPPCCPPCCIPPPIPPCIICIIIPPCIPPICPPICCPIICCCCCCCICPCCPPIPIPICPCIICPCCIPICCCPPCPIIICPCPPPIIIIICCCPCICCPPCPPCICIIIPIPICPCPPPPICPCPIPIIICCICPCIPPICCICPIIPPCCCIICPCPCCICCPICPPPPPPICCCIPCCICICIPICIIICCICPCIPIICPIPIIICCPCCIIPCCCCPIPI...

output:


result: