QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#292598#7559. Bocchi the RockjovanbenginRE 3ms4400kbC++202.8kb2023-12-28 09:19:542023-12-28 09:19:54

Judging History

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

  • [2023-12-28 09:19:54]
  • 评测
  • 测评结果:RE
  • 用时:3ms
  • 内存:4400kb
  • [2023-12-28 09:19:54]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ld = long double;

#define pb push_back
#define si(x) int(x.size())
#define all(x) x.begin(), x.end()
#define fi first
#define se second

const int N = 3000;
const int C = N + 1;
const int MOD = 998244353;

int add(int a, int b){ a += b; if(a >= MOD) a -= MOD; return a; }
int mul(int a, int b){ return (1LL*a*b)%MOD; }
int sub(int a, int b){ return add(a, MOD - b); }

int pw(int a, int b){
    if(b == 0) return 1;
    int res = pw(a, b/2);
    res = mul(res, res);
    if(b%2) res = mul(res, a);
    return res;
}

int dp[N+5][2][2][2*N+5];

string arc = " ";
string pt = " ";

int ways_arc(int i, int j){
    if(arc[i] == '?') return 1;
    if(j == 0) return (arc[i] == 'Y');
    return arc[i] == 'P';
}

int ways_pt(int i, int j){
    if(pt[i] == '?') return 1;
    if(j == 0) return (pt[i] == 'R');
    return pt[i] == 'B';
}

int main(){
    ios_base::sync_with_stdio(false), cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int n;
    cin >> n;
    string s;
    cin >> s;
    for(int i=0; i<si(s); i+=2){
        arc += s[i];
        pt += s[i+1];
    }
    dp[1][0][0][C] = ways_arc(1, 0);
    dp[1][1][1][C] = ways_arc(1, 1);
    for(int i=1; i<n; i++){
        for(int f=0; f<=1; f++){
            for(int ls=0; ls<=1; ls++){
                for(int diff=-N; diff<=N; diff++){
                    /// ista boja
                    for(int h=0; h<=1; h++){
                        int x = mul(dp[i][f][ls][diff+C], ways_arc(i + 1, ls));
                        x = mul(x, ways_pt(i, h));
                        dp[i+1][f][ls][diff+C] = add(dp[i+1][f][ls][diff+C], x);
                    }
                    /// razlicita boja
                    for(int h=0; h<=1; h++){
                        int x = mul(dp[i][f][ls][diff+C], ways_arc(i + 1, 1 ^ ls));
                        x = mul(x, ways_pt(i, h));
                        int sm = (abs(diff)%2 ? -1 : 1)*(h ? -1 : 1);
                        dp[i+1][f][1^ls][diff+C+sm] = add(dp[i+1][f][1^ls][diff+C+sm], x);
                    }
                }
            }
        }
    }
    int res = 0;
    for(int fs=0; fs<=1; fs++){
        for(int ls=0; ls<=1; ls++){
            if(fs == ls){
                for(int h=0; h<=1; h++){
                    int x = mul(dp[n][fs][ls][C], ways_pt(n, h));
                    res = add(res, x);
                }
            }
            else{
                for(int h=0; h<=1; h++){
                    int sm = -1*(h ? -1 : 1);
                    int x = mul(ways_pt(n, h), dp[n][fs][ls][C-sm]);
                    res = add(res, x);
                }
            }
        }
    }
    cout << res << "\n";
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3532kb

input:

2
????

output:

12

result:

ok 1 number(s): "12"

Test #2:

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

input:

3
??YR?B

output:

4

result:

ok 1 number(s): "4"

Test #3:

score: 0
Accepted
time: 2ms
memory: 3812kb

input:

5
YBYRPBYRYB

output:

0

result:

ok 1 number(s): "0"

Test #4:

score: 0
Accepted
time: 3ms
memory: 4364kb

input:

10
PRPBPRPRPRPBYB?R?BY?

output:

3

result:

ok 1 number(s): "3"

Test #5:

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

input:

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

output:

96

result:

ok 1 number(s): "96"

Test #6:

score: 0
Accepted
time: 3ms
memory: 4368kb

input:

10
YRPRYRY???P?YB?BYRY?

output:

32

result:

ok 1 number(s): "32"

Test #7:

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

input:

10
PBYBPRPBYRPBYRYBPRPB

output:

0

result:

ok 1 number(s): "0"

Test #8:

score: 0
Accepted
time: 3ms
memory: 4332kb

input:

10
PBPRPRYBYRYRYB?B?RYB

output:

0

result:

ok 1 number(s): "0"

Test #9:

score: 0
Accepted
time: 3ms
memory: 4304kb

input:

10
PRP?PBPRYR??Y?YRPB?R

output:

12

result:

ok 1 number(s): "12"

Test #10:

score: 0
Accepted
time: 3ms
memory: 4288kb

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: