QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#297232 | #5474. Incredibly Cute Penguin Chicks | dozicc | TL | 1ms | 5576kb | C++14 | 1.1kb | 2024-01-04 07:44:52 | 2024-01-04 07:44:54 |
Judging History
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...