QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#232481#7559. Bocchi the RocklefyWA 1ms5872kbC++142.2kb2023-10-30 15:20:332023-10-30 15:20:33

Judging History

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

  • [2023-10-30 15:20:33]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5872kb
  • [2023-10-30 15:20:33]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long 
using namespace std;
const int N=5e4+10,mod=998244353;
int add(ll x,int y){
    x+=y;
    while(x>=mod)x-=mod;
    return x;
}
char a[N<<1];
int dp[2][N][2][2];
//end colv cole
int ce[N][2],cv[N][2],c[N][2];
void solve(int op,int now,int x){
    if(x==0){
        for(int i=0;i<=1;i++)dp[op][x][0][i]=0;
        for(int i=0;i<=1;i++){
            for(int j=0;j<=1;j++)if(cv[now][i]&&ce[now][j]){
                dp[op][x][0][j]=add(dp[op][x][0][j],dp[op^1][1][i][j^1]);
            }
            dp[op][x][0][i]=add(dp[op][x][0][i],dp[op^1][x][0][i]*c[now][i]);
        }
        return;
    }
    for(int i=0;i<=1;i++)for(int j=0;j<=1;j++){
        dp[op][x][i][j]=0;
        if(cv[now][i]&&ce[now][j]&&x){//put back
            if(x==1){
                dp[op][x][i][j]=add(dp[op][x][i][j],dp[op^1][x-1][0][j^1]);
            }else dp[op][x][i][j]=add(dp[op^1][x-1][i^1][j^1],dp[op][x][i][j]);
        }
        if(cv[now][i^1]&&ce[now][j])
            dp[op][x][i][j]=add(dp[op][x][i][j],dp[op^1][x+1][i^1][j^1]);
        dp[op][x][i][j]=add(dp[op][x][i][j],dp[op^1][x][0][j]*c[now][j]);    
    }   
    
}
int main() {
    int n;
    scanf("%d%s",&n,a+1);
    int op=1;
    for(int i=1;i<=n;i++){
        int nxt=i==n?1:i+1;
        c[i][1]=(a[i*2-1]!='P'&&a[nxt*2-1]!='P')*(a[i*2]=='?'?2:1);
        c[i][0]=(a[i*2-1]!='Y'&&a[nxt*2-1]!='Y')*(a[i*2]=='?'?2:1);
        ce[i][0]=a[i*2-1]!='P'&&a[nxt*2-1]!='Y';
        ce[i][1]=a[i*2-1]!='Y'&&a[nxt*2-1]!='P';
        cv[i][0]=a[i*2]!='R';
        cv[i][1]=a[i*2]!='B';
    }
    for(int i=0;i<=1;i++)for(int j=0;j<=1;j++){
        dp[op][1][i][j]=ce[1][j]&&cv[1][i];
        dp[op][0][0][j]=c[1][j];
    }
    // for(int i=0;i<=1;i++,cout<<"\n")for(int k=0;k<=1;k++)for(int k2=0;k2<=1;k2++)cout<<dp[op][i][k][k2]<<" ";
    // cout<<dp[op][1][0][1]
    for(int i=2;i<=n;i++){
        op^=1;
        for(int j=0;j<=i;j++){
            solve(op,i,j); 
            // cout<<dp[op][j][0][0]<<" "<<dp[op][j][0][1]<<" "<<dp[op][j][1][0]<<" "<<dp[op][j][1][1]<<" \n";
        }
    }  
    int ans=0;
    for(int j=0;j<=1;j++)ans=add(ans,dp[op][0][0][j]);
    printf("%d",ans);
    return 0;
}

詳細信息

Test #1:

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

input:

2
????

output:

12

result:

ok 1 number(s): "12"

Test #2:

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

input:

3
??YR?B

output:

4

result:

ok 1 number(s): "4"

Test #3:

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

input:

5
YBYRPBYRYB

output:

0

result:

ok 1 number(s): "0"

Test #4:

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

input:

10
PRPBPRPRPRPBYB?R?BY?

output:

4

result:

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