QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#232809#7559. Bocchi the RockAFewSunsRE 1ms5912kbC++142.4kb2023-10-30 22:48:522023-10-30 22:48:52

Judging History

你现在查看的是最新测评结果

  • [2023-10-30 22:48:52]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:5912kb
  • [2023-10-30 22:48:52]
  • 提交

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[1]!=(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: 0ms
memory: 3692kb

input:

2
????

output:

12

result:

ok 1 number(s): "12"

Test #2:

score: 0
Accepted
time: 1ms
memory: 5628kb

input:

3
??YR?B

output:

4

result:

ok 1 number(s): "4"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3836kb

input:

5
YBYRPBYRYB

output:

0

result:

ok 1 number(s): "0"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3796kb

input:

10
PRPBPRPRPRPBYB?R?BY?

output:

3

result:

ok 1 number(s): "3"

Test #5:

score: 0
Accepted
time: 1ms
memory: 5908kb

input:

10
?R?R?BYB?R?R?B?B?BYR

output:

96

result:

ok 1 number(s): "96"

Test #6:

score: 0
Accepted
time: 1ms
memory: 5700kb

input:

10
YRPRYRY???P?YB?BYRY?

output:

32

result:

ok 1 number(s): "32"

Test #7:

score: 0
Accepted
time: 0ms
memory: 3716kb

input:

10
PBYBPRPBYRPBYRYBPRPB

output:

0

result:

ok 1 number(s): "0"

Test #8:

score: 0
Accepted
time: 1ms
memory: 5912kb

input:

10
PBPRPRYBYRYRYB?B?RYB

output:

0

result:

ok 1 number(s): "0"

Test #9:

score: 0
Accepted
time: 0ms
memory: 3776kb

input:

10
PRP?PBPRYR??Y?YRPB?R

output:

12

result:

ok 1 number(s): "12"

Test #10:

score: 0
Accepted
time: 0ms
memory: 3872kb

input:

10
?RYB??P??B?B?B???RPR

output:

416

result:

ok 1 number(s): "416"

Test #11:

score: -100
Runtime Error

input:

50000
YBPBYRPRPRPRPBPRPBPBPBYRPRPBPBYRPBPRYBYBPBPBPRPBPBYRYBYRPBYRYRPBYRYRYRPBYBYRPBPBYBYBPBYRPBPBYBYBYRPBPRYBPBYBPRPRYBPRPBYBPRPBYRPBYBPRYBPBPBYRYBYBYBPRYBYRPRPRPRPRYRYBPBPBPBPRPRYBYRYBPRPRPRPBYBPBPRYRPRPBYRPBYRYRPBYBYBPBYRYRPBPRYBPRYBPBPBYRPBPBYBYBPRPBYBYBYRYRPBPRPRPRPRPRYBPBPBPRYBYRPRPRYBYRPRPBYR...

output:


result: