QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#711281#9536. Athlete Welcome Ceremonycyc_43346WA 3ms22160kbC++145.4kb2024-11-05 08:53:252024-11-05 08:53:25

Judging History

This is the latest submission verdict.

  • [2024-11-05 08:53:25]
  • Judged
  • Verdict: WA
  • Time: 3ms
  • Memory: 22160kb
  • [2024-11-05 08:53:25]
  • Submitted

answer

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



int read()
{
    int res = 0;
    int x = 1;
    char ch = getchar();
    while(ch > '9' || ch < '0')
    {
        if(ch == '-')
        {
            x = -1;
        }
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9')
    {
        res = res * 10 + ch - '0';
        ch = getchar();
    }
    return res * x;
}

const int Mod = 1e9 + 7;
const int N = 309;

int n , m;
int f[N][3][N][N];
string s;
int sum[N][N][N];
int dp[N][N][N];
int cnt = 0;

void solve()
{
    cin >> n >> m;
    cin >> s;
    for(int i = 0 ; i < n ; i++)
    {
        if(s[i] == '?')
        {
            cnt++;
        }
        for(int x = 0 ; x <= cnt ; x++)
        {
            for(int y = 0 ; y <= cnt ; y++)
            {
                if(x + y > cnt)
                {
                    continue;
                }
                if(s[i] == 'a')
                {
                    if(i == 0)
                    {
                        f[i][0][x][y] = 1;
                    }
                    else
                    {
                        f[i][0][x][y] = (f[i - 1][1][x][y] + f[i - 1][2][x][y]) % Mod;
                    }
                }
                else if(s[i] == 'b')
                {
                    if(i == 0)
                    {
                        f[i][1][x][y] = 1;
                    }
                    else
                    {
                        f[i][1][x][y] = (f[i - 1][2][x][y] + f[i - 1][0][x][y]) % Mod;
                    }
                }
                else if(s[i] == 'c')
                {
                    if(i == 0)
                    {
                        f[i][2][x][y] = 1;
                    }
                    else
                    {
                        f[i][2][x][y] = (f[i - 1][0][x][y] + f[i - 1][1][x][y]) % Mod;
                    }
                }
                else
                {
                    for(int j = 0 ; j < 3 ; j++)
                    {
                        int to1 = (j + 1) % 3 , to2 = (j + 2) % 3;
                        if(j == 0 && x)
                        {
                            if(i == 0)
                            {
                                f[i][j][x][y] = 1;
                            }
                            else
                            {
                                f[i][j][x][y] = (f[i - 1][to1][x - 1][y] + f[i - 1][to2][x - 1][y]) % Mod;
                            }
                        }
                        else if(j == 1 && y)
                        {
                            if(i == 0)
                            {
                                f[i][j][x][y] = 1;
                            }
                            else
                            {
                                f[i][j][x][y] = (f[i - 1][to1][x][y - 1] + f[i - 1][to2][x][y - 1]) % Mod;
                            }
                        }
                        else if(j == 2 && ((x + y) != cnt))
                        {
                            if(i == 0)
                            {
                                f[i][j][x][y] = 1;
                            }
                            else
                            { 
                                f[i][j][x][y] = (f[i - 1][to1][x][y]+ f[i - 1][to2][x][y]) % Mod;
                            }
                        }
                    }
                }
            }
        }
    }
    for(int x = 0 ; x <= cnt ; x++)
    {
        for(int y = 0 ; y <= cnt ; y++)
        {
            int z = cnt - x - y;
            if(z < 0)
            {
                continue;
            }
            for(int j = 0 ; j < 3 ; j++)
            {
                 dp[x][y][z] = (dp[x][y][z] + f[n - 1][j][x][y]) % Mod;
            }
        }
    }

    for(int x = 0 ; x <= cnt ; x++)
    {
        for(int y = 0 ; y <= cnt ; y++)
        {
            for(int z = 0 ; z <= cnt ; z++)
            {
                if(z)
                {
                    sum[x][y][z] += sum[x][y][z - 1];
                }
                if(y)
                {
                    sum[x][y][z] += sum[x][y - 1][z];
                }
                if(x)
                {
                    sum[x][y][z] += sum[x - 1][y][z];
                }
                if(y && z)
                {
                    sum[x][y][z] -= sum[x][y - 1][z - 1];
                }
                if(x && z)
                {
                    sum[x][y][z] -= sum[x - 1][y][z - 1];
                }
                if(x && y)
                {
                    sum[x][y][z] -= sum[x - 1][y - 1][z];
                }
                if(x && y && z)
                {
                    sum[x][y][z] += sum[x - 1][y - 1][z - 1];
                }
                sum[x][y][z] += dp[x][y][z];
                sum[x][y][z] = (sum[x][y][z] % Mod + Mod) % Mod;
            }
        }
    }

    for(int i = 1 ; i <= m ; i++)
    {
        int x , y , z;
        cin >> x >> y >> z;
        cout << sum[x][y][z] << "\n";
    }
}

signed main()
{
    cin.tie(0) -> sync_with_stdio(false);
    //freopen("in1.txt" , "r" , stdin);
    //freopen("out1.txt" , "w" , stdout); 
    solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 16068kb

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: 18128kb

input:

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

output:

30
72
96

result:

ok 3 lines

Test #3:

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

input:

1 1
?
0 1 1

output:

2

result:

ok single line: '2'

Test #4:

score: -100
Wrong Answer
time: 3ms
memory: 22160kb

input:

10 10
acab?cbaca
0 2 0
1 1 2
4 2 3
1 1 1
3 5 1
0 5 2
2 2 0
1 2 5
4 3 0
1 1 3

output:

0
0
0
1
0
0
0
0
0
0

result:

wrong answer 2nd lines differ - expected: '1', found: '0'