QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#232342#7559. Bocchi the RockCharlieVinnieWA 1ms5400kbC++172.4kb2023-10-30 11:12:322023-10-30 11:12:33

Judging History

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

  • [2023-10-30 11:12:33]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5400kb
  • [2023-10-30 11:12:32]
  • 提交

answer

#include "bits/stdc++.h"
#ifdef DEBUG
#include "PrettyDebug.hpp"
#else
#define debug(...) [](auto...){}(__VA_ARGS__)
#define debuga(...) [](auto...){}(__VA_ARGS__)
#endif
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Rev(i,a,b) for(int i=a;i>=b;i--)
#define Fin(file) freopen(file,"r",stdin)
#define Fout(file) freopen(file,"w",stdout)
#define assume(expr) ((!!(expr))||(exit((fprintf(stderr,"Assumption Failed: %s on Line %d\n",#expr,__LINE__),-1)),false))
#define range basic_string_view
using namespace std; typedef long long ll;
constexpr int N=5e4+5,mod=998244353;
int n,f[2][2][2][N]; string s; // f[o][arc][col][cnt]  R=0,B=1  Y=0,P=1    0 point, 1 edge
inline void ck(int& x,int y) { x+=y-mod; x+=x>>31&mod; }
inline bool I0(char c,int o) { return c!="BR"[o]; }
inline bool I1(char c,int o) { return c!="PY"[o]; }
signed main(){
    atexit([](){cerr<<"Time = "<<clock()<<" ms"<<endl;}); ios::sync_with_stdio(0); cin.tie(0);
    cin>>n>>s; s=' '+s;
    For(u,0,1) if(I1(s[1],u)) f[0][u][0][0]=1;
    int o=0;
    For(i,1,n-1){
        memset(f[o^1],0,sizeof(f[o^1]));
        char c0=s[i*2],c1=s[i*2+1];
        For(u,0,1) For(v,0,1) For(j,0,i-1) if(f[o][u][v][j]){
            int x=f[o][u][v][j];
            if(j==0){
                if(I1(c1,u)){
                    if(I0(c0,0)) ck(f[o^1][u][0][0],x);
                    if(I0(c0,1)) ck(f[o^1][u][0][0],x);
                }
                if(I1(c1,u^1)){
                    if(I0(c0,0)) ck(f[o^1][u^1][0][1],x);
                    if(I0(c0,1)) ck(f[o^1][u^1][1][1],x);
                }
            }
            else{
                if(I1(c1,u)){
                    if(I0(c0,0)) ck(f[o^1][u][v][j],x);
                    if(I0(c0,1)) ck(f[o^1][u][v][j],x);
                }
                if(I1(c1,u^1)){
                    if(I0(c0,v  )) ck(f[o^1][u][v^1][j-1],x);
                    if(I0(c0,v^1)) ck(f[o^1][u][v^1][j+1],x);
                }
            }
        }
        o^=1;
    }
    int ans=0; For(u,0,1) For(v,0,1){
        if(I0(s[n*2],0)) ck(ans,f[o][u][v][0]);
        if(I0(s[n*2],1)) ck(ans,f[o][u][v][0]);
        if(I0(s[n*2],v)) ck(ans,f[o][u][v][1]);
    }
    cout<<ans<<'\n';
    return 0;
}

// START TYPING IF YOU DON'T KNOW WHAT TO DO
// STOP TYPING IF YOU DON'T KNOW WHAT YOU'RE DOING
// CONTINUE, NON-STOPPING, FOR CHARLIEVINNIE

// Started Coding On: October 30 Mon, 10 : 41 : 58

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
????

output:

12

result:

ok 1 number(s): "12"

Test #2:

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

input:

3
??YR?B

output:

4

result:

ok 1 number(s): "4"

Test #3:

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

input:

5
YBYRPBYRYB

output:

0

result:

ok 1 number(s): "0"

Test #4:

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

input:

10
PRPBPRPRPRPBYB?R?BY?

output:

3

result:

ok 1 number(s): "3"

Test #5:

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

input:

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

output:

96

result:

ok 1 number(s): "96"

Test #6:

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

input:

10
YRPRYRY???P?YB?BYRY?

output:

25

result:

wrong answer 1st numbers differ - expected: '32', found: '25'