QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#710071#9536. Athlete Welcome CeremonywxgmjfhyWA 0ms6616kbC++202.8kb2024-11-04 18:28:172024-11-04 18:28:17

Judging History

This is the latest submission verdict.

  • [2024-11-04 18:28:17]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 6616kb
  • [2024-11-04 18:28:17]
  • Submitted

answer

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

const int mod=998244353;

int n,q;
string s;

const int N=300;
int dp[3][N+1][N+1],g[3][N+1][N+1];

int pre[N+1][N+1];

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin>>n>>q;

    cin>>s;
    s=" "+s;

    int p=0;

    for(int i=1;i<=n;i++){
        if(s[i]=='?'){
            if(p==0){
                p++;

                dp[0][1][0]=(s[i-1]!='a'&&(i==n||s[i+1]!='a'));
                dp[1][0][1]=(s[i-1]!='b'&&(i==n||s[i+1]!='b'));
                dp[2][0][0]=(s[i-1]!='c'&&(i==n||s[i+1]!='c'));
                
                continue;
            }

            for(int t=0;t<=p;t++){
                for(int j=0;t+j<=p;j++){
                    for(int k=0;k<=2;k++){
                        g[k][t][j]=dp[k][t][j];
                        dp[k][t][j]=0;
                    }
                }
            }

            p++;

            if(s[i-1]!='a'&&(i==n||s[i+1]!='a')){
                for(int t=1;t<=p;t++){
                    for(int j=0;j+t<=p;j++){
                        if(t-1&&s[i-1]!='?')dp[0][t][j]+=g[0][t-1][j];
                        if(j)dp[0][t][j]+=g[1][t-1][j];
                        if(p-1-(t-1+j))dp[0][t][j]+=g[2][t-1][j];
                        dp[0][t][j]%=mod;
                    }
                }
            }

            if(s[i-1]!='b'&&(i==n||s[i+1]!='b')){
                for(int t=0;t<=p;t++){
                    for(int j=1;j+t<=p;j++){
                        if(t)dp[1][t][j]+=g[0][t][j-1];
                        if(j-1&&s[i-1]!='?')dp[1][t][j]+=g[1][t][j-1];
                        if(p-1-(t+j-1))dp[1][t][j]+=g[2][t][j-1];
                        dp[1][t][j]%=mod;
                    }
                }
            }

            if(s[i-1]!='c'&&(i==n||s[i+1]!='c')){
                for(int t=0;t<=p;t++){
                    for(int j=0;j+t+1<=p;j++){
                        if(t)dp[2][t][j]+=g[0][t][j];
                        if(j)dp[2][t][j]+=g[1][t][j];
                        if(p-1-(t+j)&&s[i-1]!='?')dp[2][t][j]+=g[2][t][j];
                        dp[2][t][j]%=mod;
                    }
                }
            }
        }
    }

    for(int lim=0;lim<=300;lim++){
        for(int i=0;i<=lim;i++){
            int x=(dp[0][i][lim-i]+dp[1][i][lim-i]+dp[2][i][lim-i])%mod;
            pre[lim][i]=((i==0?0:pre[lim][i-1])+x)%mod;
        }
    }

    for(int a,b,c;q--;){
        cin>>a>>b>>c;

        int mx=min(a+b,p),mn=p-c;

        int ans=0;
        
        for(int lim=mn;lim<=mx;lim++){
            ans+=pre[lim][min(a,lim)]-(lim-b==0?0:pre[lim][lim-b-1]);
            ans=(ans%mod+mod)%mod;
        }

        cout<<ans<<"\n";
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 6388kb

input:

6 3
a?b??c
2 2 2
1 1 1
1 0 2

output:

3
1
1

result:

ok 3 lines

Test #2:

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

input:

6 3
??????
2 2 2
2 3 3
3 3 3

output:

30
72
96

result:

ok 3 lines

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 6360kb

input:

1 1
?
0 1 1

output:

738192853

result:

wrong answer 1st lines differ - expected: '2', found: '738192853'