QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#297233 | #5474. Incredibly Cute Penguin Chicks | dozicc | TL | 1ms | 5540kb | C++14 | 1.1kb | 2024-01-04 07:46:12 | 2024-01-04 07:46:12 |
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()
{
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;
}
詳細信息
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...