QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#232542#7559. Bocchi the Rocksinsop90WA 1ms5208kbC++171.3kb2023-10-30 16:16:312023-10-30 16:16:31

Judging History

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

  • [2023-10-30 16:16:31]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5208kb
  • [2023-10-30 16:16:31]
  • 提交

answer

#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const int maxn = 5e4 + 5, mod = 998244353;
int f[2][2][2][maxn], ans, n;
char s[maxn];
void add(int &x, int y) {
	x += y;
	if(x >= mod) x -= mod;
}
void solve(int x) {
	f[0][x][0][0] = 1;
	int op = 1;
	for(int i = 1;i <= n;i++) {
		memset(f[op], 0, sizeof(f[op]));
		for(int j = 0;j < 2;j++) {
			for(int k = 0;k < 2;k++) {
				for(int l = 0;l < i;l++) {
					if(!f[op ^ 1][j][k][l]) continue;
					for(int u = 0;u < 2;u++) {
						if(s[2 * i + 1] == 'Y' && u) continue;
						if(s[2 * i + 1] == 'P' && !u) continue;
						for(int v = 0;v < 2;v++) {
							if(s[2 * i] == 'R' && v) continue;
							if(s[2 * i] == 'B' && !v) continue;
							if(u == j) add(f[op][u][k][l], f[op ^ 1][j][k][l]);
							else if(!l) add(f[op][u][v][1], f[op ^ 1][j][k][l]);
							else if(v == k && l == 1) add(f[op][u][0][0], f[op ^ 1][j][k][l]);
							else add(f[op][u][v][l + (v == k ? -1 : 1)], f[op ^ 1][j][k][l]);
						}
					}
				}
			}
		}
		op ^= 1;
	}
	add(ans, f[op ^ 1][x][0][0]);
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	cin >> n >> (s + 1);
	s[2 * n + 1] = '?';
	if(s[1] != 'Y') solve(1);
	if(s[1] != 'P') solve(0);
	cout << ans << '\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 5108kb

input:

2
????

output:

12

result:

ok 1 number(s): "12"

Test #2:

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

input:

3
??YR?B

output:

4

result:

ok 1 number(s): "4"

Test #3:

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

input:

5
YBYRPBYRYB

output:

0

result:

ok 1 number(s): "0"

Test #4:

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

input:

10
PRPBPRPRPRPBYB?R?BY?

output:

3

result:

ok 1 number(s): "3"

Test #5:

score: -100
Wrong Answer
time: 1ms
memory: 5176kb

input:

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

output:

56

result:

wrong answer 1st numbers differ - expected: '96', found: '56'