QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#735640#9536. Athlete Welcome CeremonysdnuwyRE 0ms0kbC++172.9kb2024-11-11 21:04:072024-11-11 21:04:14

Judging History

This is the latest submission verdict.

  • [2024-11-11 21:04:14]
  • Judged
  • Verdict: RE
  • Time: 0ms
  • Memory: 0kb
  • [2024-11-11 21:04:07]
  • Submitted

answer

//Think twice,code once.
#include<bits/stdc++.h>
#define endl '\n'
#define int long long
#define INF 0x3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#define ff first
#define ss second
#define pii pair<int,int>
#define mem(i,n) memset(i,n,sizeof i)
#define dg(a) std::cout << #a << " = " << a << endl
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

const int N=305;
const int mod=1e9+7;
int f[N][N][N][3];
int g[N][N][N];

void solve()
{
    int n,q;
    cin >> n >> q;
    string s;
    cin >> s;
    s=' '+s;
    f[0][0][0][0]=1;
    f[0][0][0][1]=1;
    f[0][0][0][2]=1;
    int cnt=0;
    for(int i=1;i<=n;i++)
    {
        if(s[i]=='?') cnt++;
        for(int j=0;j<=n;j++)
        {
            for(int k=0;k<=n;k++)
            {
                if(s[i]=='?')
                {
                    if(j!=0)
                        f[i][j][k][0]=f[i-1][j-1][k][1]+f[i-1][j-1][k][2];
                    if(k!=0)
                        f[i][j][k][1]=f[i-1][j][k-1][0]+f[i-1][j][k-1][2];
                    f[i][j][k][2]=f[i-1][j][k][0]+f[i-1][j][k][1];
                }
                else
                {
                    if(s[i]=='a')
                    {   
                        f[i][j][k][0]=f[i-1][j][k][1]+f[i-1][j][k][2];
                    }
                    else if(s[i]=='b')
                    {
                        f[i][j][k][1]=f[i-1][j][k][2]+f[i-1][j][k][0];
                    }
                    else
                    {
                        f[i][j][k][2]=f[i-1][j][k][1]+f[i-1][j][k][0];
                    }
                }
                f[i][j][k][0]%=mod;
                f[i][j][k][1]%=mod;
                f[i][j][k][2]%=mod;
            }
        }
    }
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=n;j++)
        {
            if(i+j>cnt) break;
            g[i][j][cnt-i-j]=(f[n][i][j][0]+f[n][i][j][1]+f[n][i][j][2])%mod;
        }
    }
    for(int i=0;i<=300;i++)
    {
        for(int j=0;j<=300;j++)
        {
            for(int k=0;k<=300;k++)
            {
                (g[i][j][k]+=g[i-1][j][k])%=mod;
            }
        }
    }
    for(int i=0;i<=300;i++)
    {
        for(int j=0;j<=300;j++)
        {
            for(int k=0;k<=300;k++)
            {
                (g[i][j][k]+=g[i][j-1][k])%=mod;
            }
        }
    }
    for(int i=0;i<=300;i++)
    {
        for(int j=0;j<=300;j++)
        {
            for(int k=0;k<=300;k++)
            {
                (g[i][j][k]+=g[i][j][k-1])%=mod;;
            }
        }
    }   
    while(q--)
    {
        int x,y,z;
        cin >> x >> y >> z;
        cout << g[x][y][z]*500000004%mod << endl;
    }

}

int32_t main()
{
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    int t = 1;
    // std::cin >> t;
    while(t--) solve();
    return 0;
}

详细

Test #1:

score: 0
Runtime Error

input:

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

output:


result: