QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#232552 | #7559. Bocchi the Rock | sinsop90 | WA | 9945ms | 5160kb | C++14 | 1.3kb | 2023-10-30 16:27:07 | 2023-10-30 16:27:08 |
Judging History
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) {
memset(f[0], 0, sizeof(f[0]));
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][k ^ 1][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] = s[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: 1ms
memory: 4948kb
input:
2 ????
output:
12
result:
ok 1 number(s): "12"
Test #2:
score: 0
Accepted
time: 0ms
memory: 4880kb
input:
3 ??YR?B
output:
4
result:
ok 1 number(s): "4"
Test #3:
score: 0
Accepted
time: 1ms
memory: 4940kb
input:
5 YBYRPBYRYB
output:
0
result:
ok 1 number(s): "0"
Test #4:
score: 0
Accepted
time: 1ms
memory: 4884kb
input:
10 PRPBPRPRPRPBYB?R?BY?
output:
3
result:
ok 1 number(s): "3"
Test #5:
score: 0
Accepted
time: 1ms
memory: 4984kb
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: 4948kb
input:
10 YRPRYRY???P?YB?BYRY?
output:
32
result:
ok 1 number(s): "32"
Test #7:
score: 0
Accepted
time: 1ms
memory: 4952kb
input:
10 PBYBPRPBYRPBYRYBPRPB
output:
0
result:
ok 1 number(s): "0"
Test #8:
score: 0
Accepted
time: 1ms
memory: 4952kb
input:
10 PBPRPRYBYRYRYB?B?RYB
output:
0
result:
ok 1 number(s): "0"
Test #9:
score: 0
Accepted
time: 1ms
memory: 4956kb
input:
10 PRP?PBPRYR??Y?YRPB?R
output:
12
result:
ok 1 number(s): "12"
Test #10:
score: 0
Accepted
time: 0ms
memory: 5112kb
input:
10 ?RYB??P??B?B?B???RPR
output:
416
result:
ok 1 number(s): "416"
Test #11:
score: -100
Wrong Answer
time: 9945ms
memory: 5160kb
input:
50000 YBPBYRPRPRPRPBPRPBPBPBYRPRPBPBYRPBPRYBYBPBPBPRPBPBYRYBYRPBYRYRPBYRYRYRPBYBYRPBPBYBYBPBYRPBPBYBYBYRPBPRYBPBYBPRPRYBPRPBYBPRPBYRPBYBPRYBPBPBYRYBYBYBPRYBYRPRPRPRPRYRYBPBPBPBPRPRYBYRYBPRPRPRPBYBPBPRYRPRPBYRPBYRYRPBYBYBPBYRYRPBPRYBPRYBPBPBYRPBPBYBYBPRPBYBYBYRYRPBPRPRPRPRPRYBPBPBPRYBYRPRPRYBYRPRPBYR...
output:
172815936
result:
wrong answer 1st numbers differ - expected: '0', found: '172815936'