QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#232580 | #7559. Bocchi the Rock | lefy | WA | 0ms | 3760kb | C++23 | 2.7kb | 2023-10-30 16:53:28 | 2023-10-30 16:53:28 |
Judging History
answer
#include <bits/stdc++.h>
#pragma GCC optimize(3)
using namespace std;
const int N=5e4+10,mod=998244353;
char a[N<<1];
int dp[2][N][2][2];
//end colv cole
int ce[N][2],cv[N][2],c[N][2];
int main() {
// freopen("1.in","r",stdin);
int n;
scanf("%d%s",&n,a+1);
int op=1;
for(int i=1;i<=n;i++){
int nxt=i==n?1:i+1;int j=i*2-1,k=nxt*2-1;
c[i][1]=(a[j]!='P'&&a[k]!='P')*(a[i*2]=='?'?2:1);
c[i][0]=(a[j]!='Y'&&a[k]!='Y')*(a[i*2]=='?'?2:1);
ce[i][0]=a[j]!='P'&&a[k]!='Y';
ce[i][1]=a[j]!='Y'&&a[k]!='P';//PY
j=i*2;
cv[i][0]=a[j]!='R';
cv[i][1]=a[j]!='B';
}
for(int i=0;i<=1;i++)for(int j=0;j<=1;j++){
dp[op][1][i][j]=ce[1][j]&&cv[1][i];
dp[op][0][0][j]=c[1][j];
}
// for(int i=0;i<=1;i++,cout<<"\n")for(int k=0;k<=1;k++)for(int k2=0;k2<=1;k2++)cout<<dp[op][i][k][k2]<<" ";
// cout<<"\n";
// cout<<dp[op][1][0][1]
for(register int now=2;now<=n;now++){
op^=1;
for(register int x=0;x<=now;x++){
if(x==0){
for(register int i=0;i<=1;i++)dp[op][x][0][i]=0;
for(register int i=0;i<=1;i++){
for(register int j=0;j<=1;j++)if(cv[now][i]&&ce[now][j]){
int &val=dp[op][x][0][j];
val+=dp[op^1][1][i][j^1];
val=val>=mod?val-mod:val;
}
int &val=dp[op][x][0][i],w=dp[op^1][x][0][i];
if(c[now][i]>=1){
val=val+w>=mod?val+w-mod:val+w;
val=c[now][i]==2?(val=val+w>=mod?val+w-mod:val+w):val;
}
}
}else
for(register int i=0;i<=1;i++)for(register int j=0;j<=1;j++){
int &val=dp[op][x][i][j],w=dp[op^1][x][i][j];
//put back
val=cv[now][i]&&ce[now][j]?(x==1?dp[op^1][x-1][0][j^1]:dp[op^1][x-1][i^1][j^1]):0;
if(cv[now][i^1]&&ce[now][j]){
val+=dp[op^1][x+1][i^1][j^1];
val=val>=mod?val-mod:val;
}
if(c[now][i]>=1){
val=val+w>=mod?val+w-mod:val+w;
val=c[now][i]==2?(val=val+w>=mod?val+w-mod:val+w):val;
}
}
// cout<<dp[op][j][0][0]<<" "<<dp[op][j][0][1]<<" "<<dp[op][j][1][0]<<" "<<dp[op][j][1][1]<<" \n";
}
// cout<<"\n";
}
int ans=dp[op][0][0][0]+dp[op][0][0][1];;
printf("%d",ans>=mod?ans-mod:ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3656kb
input:
2 ????
output:
12
result:
ok 1 number(s): "12"
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3760kb
input:
3 ??YR?B
output:
3
result:
wrong answer 1st numbers differ - expected: '4', found: '3'