QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#333213 | #7559. Bocchi the Rock | Famiglistmo | WA | 0ms | 3624kb | C++17 | 1.3kb | 2024-02-19 18:37:28 | 2024-02-19 18:37:28 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int mod=998244353;
const int N=5e4+5;
int a[N<<1],f[2][N][2][2];
char s[N<<1];
int n;
void inc(int &a,int b){a=a+b>=mod?a+b-mod:a+b;}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cin>>n>>(s+1);
for(int i=1;i<=(n<<1);++i)
if(s[i]=='?') a[i]=2;
else if(s[i]=='Y'||s[i]=='R') a[i]=0;
else a[i]=1;
for(int e=0;e<2;++e)
if(e^a[1]^1) f[0][1][e][0]=f[0][1][e][1]=1;
for(int i=1;i<n;++i) {
int cur=i&1;
memset(f[cur],0,(i+2)*4*sizeof(int));
for(int j=1;j<=i;++j)
for(int e=0;e<2;++e) if(e^a[i<<1|1]^1)
for(int v=0;v<2;++v) if(v^a[i<<1]^1)
inc(f[cur][j][e][0],f[cur^1][j][e][0]),
inc(f[cur][j][e][1],f[cur^1][j][e][1]),
inc(f[cur][j+1][e][v],f[cur^1][j][e^1][v^1]),
inc(f[cur][j-1][e][v^1],f[cur^1][j][e^1][v]);
}
int cur=(n-1)&1,ans=0;
if(0^a[n<<1]^1) inc(ans,f[cur][1][0][0]),inc(ans,f[cur][1][1][0]);
if(1^a[n<<1]^1) inc(ans,f[cur][1][0][1]),inc(ans,f[cur][1][1][1]);
if(0^a[n<<1]^1) inc(ans,f[cur][2][0][0]),inc(ans,f[cur][2][1][0]);
if(1^a[n<<1]^1) inc(ans,f[cur][2][0][1]),inc(ans,f[cur][2][1][1]);
cout<<ans<<'\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3556kb
input:
2 ????
output:
12
result:
ok 1 number(s): "12"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3568kb
input:
3 ??YR?B
output:
4
result:
ok 1 number(s): "4"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3572kb
input:
5 YBYRPBYRYB
output:
0
result:
ok 1 number(s): "0"
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 3624kb
input:
10 PRPBPRPRPRPBYB?R?BY?
output:
2
result:
wrong answer 1st numbers differ - expected: '3', found: '2'