QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#713305#9536. Athlete Welcome CeremonyLnianWA 1ms13552kbC++203.2kb2024-11-05 18:56:202024-11-05 18:56:20

Judging History

This is the latest submission verdict.

  • [2024-11-05 18:56:20]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 13552kb
  • [2024-11-05 18:56:20]
  • Submitted

answer

#include <bits/stdc++.h>

using namespace std;

using i64 = long long;
using i128 = __int128;
using ull = unsigned long long;
#define pll pair<ll, ll>
#define pii pair<int, int>
#define vi vector<int>
#define fir(i, a, b) for (int i = a; i <= b; i++)
#define pqi priority_queue<int> // 优先队列

#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
// #define int long long

const int mod = 1e9 + 7;
void upd(int &a, int b)
{
    a += b;
    if (a >= mod)
        a -= mod;
}

int n, q;
int f[303][303][303][3];
int g[303][303][303];
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    std::cin >> n >> q;
    std::string s;
    std::cin >> s;
    if (s[0] == 'a' || s[0] == '?')
        f[1][1][0][0] = 1;
    if (s[0] == 'b' || s[0] == '?')
        f[1][0][1][1] = 1;
    if (s[0] == 'c' || s[0] == '?')
        f[1][0][0][2] = 1;

    for (int i = 1; i < n; i++)
    {
        for (int a = 0; a <= i; a++)
        {
            for (int b = 0; a + b <= i; b++)
            {
                for (int x = 0; x < 3; x++)
                {
                    if (s[i] == 'a' || s[i] == '?')
                        if (x != 0)
                        {
                            upd(f[i + 1][a + 1][b][0], f[i][a][b][x]);
                        }
                    if (s[i] == 'b' || s[i] == '?')
                        if (x != 1)
                        {
                            upd(f[i + 1][a][b + 1][1], f[i][a][b][x]);
                        }
                    if (s[i] == 'c' || s[i] == '?')
                        if (x != 2)
                        {
                            upd(f[i + 1][a][b][2], f[i][a][b][x]);
                        }
                }
            }
        }
    }

    int ca = 0, cb = 0, cc = 0;
    for (int i = 0; i <= n; i++)
    {
        for (int j = 0; i + j <= n; j++)
        {
            for (int x = 0; x < 3; x++)
            {
                upd(g[i][j][n - i - j], f[n][i][j][x]);
            }
        }
    }

    for (int i = 0; i <= n; i++)
        for (int j = 0; j <= n; j++)
            for (int k = 0; k <= n; k++)
                if (i)
                    upd(g[i][j][k], g[i - 1][j][k]);
    for (int i = 0; i <= n; i++)
    {
        for (int j = 0; j <= n; j++)
        {
            for (int k = 0; k <= n; k++)
            {
                if (j)
                    upd(g[i][j][k], g[i][j - 1][k]);
            }
        }
    }

    for (int i = 0; i <= n; i++)
    {
        for (int j = 0; j <= n; j++)
        {
            for (int k = 0; k <= n; k++)
            {
                if (k)
                    upd(g[i][j][k], g[i][j][k - 1]);
            }
        }
    }

    for (int i = 0; i < n; i++)
    {
        if (s[i] == 'a')
            ca++;
        if (s[i] == 'b')
            cb++;
        if (s[i] == 'c')
            cc++;
    }

    while (q--)
    {
        int x, y, z;
        std::cin >> x >> y >> z;
        x = std::min(n, x + ca);
        y = std::min(n, y + ca);
        z = std::min(n, z + cc);

        std::cout << g[x][y][z] << "\n";
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 1ms
memory: 5752kb

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

input:

1 1
?
0 1 1

output:

2

result:

ok single line: '2'

Test #4:

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

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
1
1
1
1
0
1
1
1
1

result:

ok 10 lines

Test #5:

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

input:

10 10
?c?c?cbac?
10 5 1
5 8 7
9 2 6
5 7 1
5 2 6
5 6 5
5 10 3
9 1 10
2 5 9
1 2 9

output:

16
16
11
16
11
16
16
5
11
0

result:

ok 10 lines

Test #6:

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

input:

50 100
?abacbacab?cbcbcb?acabcbabcbcacbababc?caba?acacbca
8 3 8
2 4 8
8 7 3
0 9 2
10 8 7
7 6 5
4 10 2
6 9 3
3 6 6
9 10 8
2 5 8
8 1 0
3 5 0
1 0 6
5 0 8
6 5 5
1 7 9
7 7 10
4 7 5
6 6 4
10 1 2
4 1 7
10 0 8
7 6 3
1 9 1
4 7 2
8 4 0
8 6 1
5 10 4
5 8 2
5 8 4
4 5 9
5 2 1
1 10 9
4 10 1
8 4 3
8 9 9
8 0 1
0 8 0...

output:

8
8
8
0
8
8
6
8
8
8
8
0
0
0
1
8
4
8
8
8
2
4
1
8
1
6
0
2
8
6
8
8
1
4
2
8
8
0
0
8
2
0
8
8
8
4
8
8
8
8
2
0
0
4
8
8
1
8
7
6
7
0
8
8
8
0
4
7
8
4
0
8
0
4
8
8
8
7
8
4
7
2
8
8
8
0
2
2
8
8
8
4
4
0
8
0
8
8
1
1

result:

ok 100 lines

Test #7:

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

input:

50 100
b????????bca?????c?b??ca?acac?b?b???ca?ab???a?a???
35 43 36
12 49 47
7 11 34
38 44 22
42 17 10
49 8 38
18 26 44
6 18 14
28 29 6
48 32 47
29 15 48
1 5 33
24 17 18
10 27 32
19 10 34
2 23 9
14 24 39
46 12 34
9 49 26
21 8 46
43 43 3
31 16 2
8 27 7
24 41 35
17 25 31
0 13 47
24 31 23
33 40 30
36 39...

output:

34272000
31599360
658144
34272000
17637520
27933952
34272000
93044
415832
34272000
34272000
0
34272000
16360704
33886976
0
34272000
34272000
7896832
27933952
718
24
0
34272000
34272000
0
34272000
34272000
34272000
34239232
0
20630016
34256640
34272000
34272000
27933952
30493248
34256640
32254720
0
1...

result:

wrong answer 3rd lines differ - expected: '497244', found: '658144'