QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#232803 | #7559. Bocchi the Rock | AFewSuns | WA | 1ms | 5856kb | C++14 | 2.4kb | 2023-10-30 22:39:23 | 2023-10-30 22:39:23 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
namespace my_std{
#define ll long long
#define bl bool
ll my_pow(ll a,ll b,ll mod){
ll res=1;
if(!b) return 1;
while(b){
if(b&1) res=(res*a)%mod;
a=(a*a)%mod;
b>>=1;
}
return res;
}
ll qpow(ll a,ll b){
ll res=1;
if(!b) return 1;
while(b){
if(b&1) res*=a;
a*=a;
b>>=1;
}
return res;
}
#define db double
#define pf printf
#define pc putchar
#define fr(i,x,y) for(register ll i=(x);i<=(y);i++)
#define pfr(i,x,y) for(register ll i=(x);i>=(y);i--)
#define go(u) for(ll i=head[u];i;i=e[i].nxt)
#define enter pc('\n')
#define space pc(' ')
#define fir first
#define sec second
#define MP make_pair
#define il inline
#define inf 8e18
#define random(x) rand()*rand()%(x)
#define inv(a,mod) my_pow((a),(mod-2),(mod))
il ll read(){
ll sum=0,f=1;
char ch=0;
while(!isdigit(ch)){
if(ch=='-') f=-1;
ch=getchar();
}
while(isdigit(ch)){
sum=sum*10+(ch^48);
ch=getchar();
}
return sum*f;
}
il void write(ll x){
if(x<0){
x=-x;
pc('-');
}
if(x>9) write(x/10);
pc(x%10+'0');
}
il void writeln(ll x){
write(x);
enter;
}
il void writesp(ll x){
write(x);
space;
}
}
using namespace my_std;
#define mod 998244353
ll n,a[100010],f[2020][2020][2][2],ans=0;
char s[100010];
int main(){
n=read();
scanf("%s",s+1);
fr(i,1,2*n){
if(s[i]=='?') a[i]=2;
else if(s[i]=='Y'||s[i]=='R') a[i]=0;
else a[i]=1;
}
fr(i,0,1) if(a[i]!=(i^1)) f[0][1][i][0]=1;
fr(i,1,n-1){
fr(p,0,1){
if(a[2*i+1]==(p^1)) continue;
fr(q,0,1){
if(a[2*i]==(q^1)) continue;
f[i][1][p][0]=(f[i][1][p][0]+f[i-1][1][p][0])%mod;
f[i][2][p][q]=(f[i][2][p][q]+f[i-1][1][p^1][0])%mod;
}
}
fr(j,2,i){
fr(p,0,1){
if(a[2*i+1]==(p^1)) continue;
fr(q,0,1){
if(a[2*i]==(q^1)) continue;
f[i][j][p][0]=(f[i][j][p][0]+f[i-1][j][p][0])%mod;
f[i][j][p][1]=(f[i][j][p][1]+f[i-1][j][p][1])%mod;
f[i][j+1][p][q]=(f[i][j+1][p][q]+f[i-1][j][p^1][q^1])%mod;
f[i][j-1][p][q^1]=(f[i][j-1][p][q^1]+f[i-1][j][p^1][q])%mod;
}
}
}
fr(j,0,1){
f[i][1][j][0]=(f[i][1][j][0]+f[i][1][j][1])%mod;
f[i][1][j][1]=0;
}
}
ans=(f[n-1][1][0][0]+f[n-1][1][1][0])%mod;
if(a[2*n]==2) ans=ans*2%mod;
if(a[2*n]!=1) ans=(ans+f[n-1][2][0][0]+f[n-1][2][1][0])%mod;
if(a[2*n]!=0) ans=(ans+f[n-1][2][0][1]+f[n-1][2][1][1])%mod;
write(ans);
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5620kb
input:
2 ????
output:
12
result:
ok 1 number(s): "12"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5856kb
input:
3 ??YR?B
output:
4
result:
ok 1 number(s): "4"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3824kb
input:
5 YBYRPBYRYB
output:
0
result:
ok 1 number(s): "0"
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 3868kb
input:
10 PRPBPRPRPRPBYB?R?BY?
output:
5
result:
wrong answer 1st numbers differ - expected: '3', found: '5'