QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#292609#7559. Bocchi the RockjovanbenginWA 6ms6556kbC++202.8kb2023-12-28 09:32:342023-12-28 09:32:35

Judging History

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

  • [2023-12-28 09:32:35]
  • 评测
  • 测评结果:WA
  • 用时:6ms
  • 内存:6556kb
  • [2023-12-28 09:32:34]
  • 提交

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 = 50000;
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[2][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%2][f][ls][diff+C], ways_arc(i + 1, ls));
                        x = mul(x, ways_pt(i, h));
                        dp[(i+1)%2][f][ls][diff+C] = add(dp[(i+1)%2][f][ls][diff+C], x);
                    }
                    /// razlicita boja
                    for(int h=0; h<=1; h++){
                        int x = mul(dp[i%2][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)%2][f][1^ls][diff+C+sm] = add(dp[(i+1)%2][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%2][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%2][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: 5ms
memory: 5044kb

input:

2
????

output:

12

result:

ok 1 number(s): "12"

Test #2:

score: -100
Wrong Answer
time: 6ms
memory: 6556kb

input:

3
??YR?B

output:

6

result:

wrong answer 1st numbers differ - expected: '4', found: '6'