QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#215755 | #7559. Bocchi the Rock | ucup-team1209 | WA | 2230ms | 4596kb | C++14 | 2.6kb | 2023-10-15 13:23:28 | 2023-10-15 13:23:29 |
Judging History
answer
#include <bits/stdc++.h>
#define cs const
#define pb push_back
using namespace std;
cs int N = 5e4 + 5;
cs int mod = 998244353;
int add(int a, int b) {
return a + b >= mod ? a + b - mod : a + b;
}
int dec(int a, int b) {
return a - b < 0 ? a - b + mod : a - b;
}
int mul(int a, int b) {
return 1ll * a * b % mod;
}
void Add(int &a, int b){
a = add(a, b);
}
void Dec(int &a, int b) {
a = dec(a, b);
}
void Mul(int &a, int b) {
a = mul(a, b);
}
int ksm(int a, int b) {
int c = 1;
for(; b; b >>= 1, Mul(a, a))
if(b & 1) Mul(c, a);
return c;
}
int F(char c) {
if(c == 'Y' || c == 'R') return 1;
if(c == 'P' || c == 'B') return 2;
return 3;
}
int n;
char S[N * 2];
int dp[2][N / 2][2][2];
int main() {
#ifdef zqj
freopen("1.in","r",stdin);
#endif
cin >> n;
scanf("%s", S);
int now = 0, nxt = 1;
dp[0][0][0][0] = dp[0][0][0][1] = 1;
S[n * 2] = S[0];
for(int i = 1; i <= n; i++) {
int a = F(S[i * 2 - 1]), b = F(S[i * 2]), c;
for(int j = min(i - 1, n / 2); j >= 0; j--)
for(int o : {0, 1}) for(int e : {0, 1}) dp[nxt][j][o][e] = 0;
for(int j = min(i - 1, n / 2); j >= 0; j--) {
for(int o : {0, 1})
for(int e : {0, 1})
if(c = dp[now][j][o][e]) {
if(b & (e + 1)) Add(dp[nxt][j][o][e], c + (a == 3 ? c : 0));
if(j == 0) {
assert(o == 0);
if(b & ((e ^ 1) + 1)) {
if(a & 1) Add(dp[nxt][j + 1][0][e ^ 1], c);
if(a & 2) Add(dp[nxt][j + 1][1][e ^ 1], c);
}
} else {
if(b & ((e ^ 1) + 1)) {
if(a & 1) {
if(o == 0) Add(dp[nxt][j - 1][j == 1 ? 0 : 1][e ^ 1], c);
else Add(dp[nxt][j + 1][0][e ^ 1], c);
}
if(a & 2) {
if(o == 0) Add(dp[nxt][j + 1][1][e ^ 1], c);
else Add(dp[nxt][j - 1][0][e ^ 1], c);
}
}
}
}
} swap(now, nxt);
// cout<<a<<' '<<b<<endl;
// for(int j=0; j<=i;j++)
// for(int k:{0,1})
// for(int l:{0,1}){
// if(dp[i][j][k][l])cerr<<i<<' '<<j<<' '<<k<<' '<<l<<' '<<dp[i][j][k][l]<<endl;
// }
} int sum = 0;
for(int i = 0; i < 2; i++)
for(int j = 0; j < 2; j++)
Add(sum, dp[now][0][i][j]);
cout << sum << '\n';
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3712kb
input:
2 ????
output:
12
result:
ok 1 number(s): "12"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3692kb
input:
3 ??YR?B
output:
4
result:
ok 1 number(s): "4"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
5 YBYRPBYRYB
output:
0
result:
ok 1 number(s): "0"
Test #4:
score: 0
Accepted
time: 1ms
memory: 3680kb
input:
10 PRPBPRPRPRPBYB?R?BY?
output:
3
result:
ok 1 number(s): "3"
Test #5:
score: 0
Accepted
time: 1ms
memory: 3520kb
input:
10 ?R?R?BYB?R?R?B?B?BYR
output:
96
result:
ok 1 number(s): "96"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3496kb
input:
10 YRPRYRY???P?YB?BYRY?
output:
32
result:
ok 1 number(s): "32"
Test #7:
score: 0
Accepted
time: 1ms
memory: 3524kb
input:
10 PBYBPRPBYRPBYRYBPRPB
output:
0
result:
ok 1 number(s): "0"
Test #8:
score: 0
Accepted
time: 0ms
memory: 3736kb
input:
10 PBPRPRYBYRYRYB?B?RYB
output:
0
result:
ok 1 number(s): "0"
Test #9:
score: 0
Accepted
time: 0ms
memory: 3520kb
input:
10 PRP?PBPRYR??Y?YRPB?R
output:
12
result:
ok 1 number(s): "12"
Test #10:
score: 0
Accepted
time: 0ms
memory: 3680kb
input:
10 ?RYB??P??B?B?B???RPR
output:
416
result:
ok 1 number(s): "416"
Test #11:
score: 0
Accepted
time: 2185ms
memory: 4396kb
input:
50000 YBPBYRPRPRPRPBPRPBPBPBYRPRPBPBYRPBPRYBYBPBPBPRPBPBYRYBYRPBYRYRPBYRYRYRPBYBYRPBPBYBYBPBYRPBPBYBYBYRPBPRYBPBYBPRPRYBPRPBYBPRPBYRPBYBPRYBPBPBYRYBYBYBPRYBYRPRPRPRPRYRYBPBPBPBPRPRYBYRYBPRPRPRPBYBPBPRYRPRPBYRPBYRYRPBYBYBPBYRYRPBPRYBPRYBPBPBYRPBPBYBYBPRPBYBYBYRYRPBPRPRPRPRPRYBPBPBPRYBYRPRPRYBYRPRPBYR...
output:
0
result:
ok 1 number(s): "0"
Test #12:
score: 0
Accepted
time: 2178ms
memory: 4432kb
input:
50000 YRPBPBYRYRYRYBYBYRPBPBPBPBPBYRYBPBPRYBPBYRYRPRYBYBYBYRPRPBPBPRYRPBYBYBPBYRYRPRPBPBPBPRYBYBYRYRPRPRYBPRPBYRPBPRYRPRYBPRYBYBYRYRYBYRYRYBYRPBPBPBYBPBPRPBPRYRPRYBYBPBPRPBPBPRPRPBYRYRPBPBPBYRPBYBYBYRPBPRPBPRYBPRPRYBPRPBPBYRYRYRYBYRPRPRYBYBYBPBPRPBPRYRYRPRPRPBPBPRPRPBYBYRPRPRPBYBYRPBYBPRPRPRPRPRPBPB...
output:
0
result:
ok 1 number(s): "0"
Test #13:
score: 0
Accepted
time: 2141ms
memory: 4596kb
input:
50000 PRPRYBPBYBYBPBYRPBYRYBPBPBPRPRPBYBYRPRPRPRPRPRYRYBYRPBPBPRYRPRPBPRPBPRPRPRPBYRYRYRPBYBYRYRPRPRPRPRYBYBYBYBPBPRPBPBPRYRPRYRPRPRYRPRPBPBYRYBPRPRYRPBPBYBYBPBYRPBPRYRPRYRYBPBPBPRPBPRPRPRYBPBPBYBYBPRYRPRYRPBYRYBYRYRPBYBPBPRPRYRPRYBYRPRPRYBYBYBPBYRYRYRYRYRYRPBYBYRYRYBYRPRYRPBPBYBYRYBPBYBPRYBPBYRYBPR...
output:
0
result:
ok 1 number(s): "0"
Test #14:
score: 0
Accepted
time: 2143ms
memory: 4484kb
input:
50000 YRPRPBPRYRYRPRYBPBYRPRPBYRYRYRPBPBYRPRYBYBYBPRYRPBPRPBPBYRPRPRPBPBYBYBPRPRPRYRYRYBYRPBYBPBPRYBPRYBYBYBPBYBYBPBPBPRYRPRPBYRYBYRPRYBYRPRYRPRPRYRPBYRYRYBYRYRPRYRYRPBPRPBYRYRPBYRPBPBPBPRPBYBYBPRYBPBPBYRYRYBYRPRPBPRYBPRPBYRPBYBYBPBPRPBYRYRPRPBPRPBPBYRPRPBYRPRPRYRYRPBYBYBPBPBYBPBYBYRYBYRPBPBPBPRYRPB...
output:
0
result:
ok 1 number(s): "0"
Test #15:
score: 0
Accepted
time: 2230ms
memory: 4392kb
input:
50000 YBPBYRPRYRPRPBPBYBYRPBYRPBPRPRPBPBPBYRYBYRPBYRYRPBYRPRPRYBPRYRYBYBPRPRYBYBPRPRPRYRPRYBPRPBYRPBYRPBYRPRPBPBPRPBPBYRYBPRPBPBPBPBYRYRPRPRYBYRPRYBYBYBYBYRYRPBPRYRYRPRYBPRPBPRPRPRPRPBPRPBYBPBPBPBYRPBYBPBPRPBYRPRPRYRYBYRPRPBPRYBYRPBPRPBPRYRPRYBYRYBYBPRPRPRPBYRPBPBYRYRPBPRYBPRYBPRYBPRYBYRPBYBPBPBYRPR...
output:
0
result:
ok 1 number(s): "0"
Test #16:
score: -100
Wrong Answer
time: 40ms
memory: 3576kb
input:
5000 PR?BPB?BY?PRY??RPB?R??YBY?P?YRPBYBPRP?YBYBYRPRPB?BPBPR?RYR??Y??RYR?BPRYR?RPRP?Y?PRY?Y?YB??PBYRYR?RPB?BPB?BY?P?Y?YBY??RPB?BPRPBY???PRP?YB?R?RP?PR?BPB???R?B?RP?PBYB?BPRYBP?P??B?RPRP???P???PRYB?RYRP?Y??RPR?BP?PR?BPBPRYR?B??PB??YBPB?B?BY?YB?RY?PR?RYB???BYBP?Y??RYRYB?RYBYBPBYRYBP?YBYR?RPBYBY?YRP??R?...
output:
227528420
result:
wrong answer 1st numbers differ - expected: '101508706', found: '227528420'