QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#722064#9536. Athlete Welcome Ceremonywangshengzhe#WA 0ms22052kbC++143.2kb2024-11-07 17:38:162024-11-07 17:38:24

Judging History

This is the latest submission verdict.

  • [2024-11-07 17:38:24]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 22052kb
  • [2024-11-07 17:38:16]
  • Submitted

answer

#include<bits/stdc++.h>

using namespace std;
using  LL = long long;

#define rep(i,a,b) for(int i = a;i<=b;i++)
#define pre(i, a, b) for(int i = a;i >= b;i--)
const int mod = 1e9 + 7;
#define int long long

int n, q;
string s;
int dp[305][305][305][3];
int sum[305][305][305];

void solve()
{
    cin >> n >> q;
    cin >> s;
    s = " " + s;
    int ma = 0, mb = 0, mc = 0;
    if (s[1] == '?')
    {
        dp[1][0][0][0] = 1;
        dp[0][1][0][1] = 1;
        dp[0][0][1][2] = 1;
    }
    else
    {
        int x = s[1] - 'a';
        if(x == 0) dp[1][0][0][0] = 1;
        else if(x == 1) dp[0][1][0][1] = 1;
        else dp[0][0][1][1] = 1;
        if (s[1] == 'a') ma++;
        if (s[1] == 'b') mb++;
        if (s[1] == 'c') mc++;
    }
    rep(i, 2, n)
    {
        if (s[i] == 'a') ma++;
        if (s[i] == 'b') mb++;
        if (s[i] == 'c') mc++;
        rep(aa, ma, i)
        {
            rep(bb, mb, i)
            {
                if (aa + bb > i) continue;
                int cc = i - aa - bb;
                if (cc < mc) continue;
                if (s[i] != '?')
                {
                    int x = s[i] - 'a';
                    if (x == 0) dp[aa][bb][cc][x] = (dp[aa - 1][bb][cc][(x + 1) % 3] + dp[aa - 1][bb][cc][(x + 2) % 3]) % mod;
                    else if (x == 1) dp[aa][bb][cc][x] = (dp[aa][bb - 1][cc][(x + 1) % 3] + dp[aa][bb - 1][cc][(x + 2) % 3]) % mod;
                    else if (x == 2) dp[aa][bb][cc][x] = (dp[aa][bb][cc - 1][(x + 1) % 3] + dp[aa][bb][cc - 1][(x + 2) % 3]) % mod;
                }
                else
                {
                    int x = 0;
                    if (aa != 0) dp[aa][bb][cc][x] = (dp[aa - 1][bb][cc][(x + 1) % 3] + dp[aa - 1][bb][cc][(x + 2) % 3]) % mod;
                    x = 1;
                    if (bb != 0) dp[aa][bb][cc][x] = (dp[aa][bb - 1][cc][(x + 1) % 3] + dp[aa][bb - 1][cc][(x + 2) % 3]) % mod;
                    x = 2;
                    if (cc != 0) dp[aa][bb][cc][x] = (dp[aa][bb][cc - 1][(x + 1) % 3] + dp[aa][bb][cc - 1][(x + 2) % 3]) % mod;
                }
                if (aa + bb + cc == n)
                {
                    sum[aa][bb][cc] = (dp[aa][bb][cc][0] + dp[aa][bb][cc][1] + dp[aa][bb][cc][2]) % mod;
                }
            }
        }
    }
    rep(i, 0, n)
        rep(k, 0, n)
            rep(j, 0, n)
                if(i != 0) sum[i][k][j] = (sum[i][k][j] + sum[i - 1][k][j]) % mod;

    rep(i, 0, n)
        rep(k, 0, n)
        rep(j, 0, n)
        if (k != 0) sum[i][k][j] = (sum[i][k][j] + sum[i][k - 1][j]) % mod;

    rep(i, 0, n)
        rep(k, 0, n)
        rep(j, 0, n)
        if (j != 0) sum[i][k][j] = (sum[i][k][j] + sum[i][k][j - 1]) % mod;
    int aaa = 0, bbb = 0, ccc =  0;
    rep(i, 1, n) {
        if (s[i] == 'a') aaa++;
        else if (s[i] == 'b') bbb++;
        else if (s[i] == 'c') ccc++;
    }
    while (q--)
    {
        int x, y, z; cin >> x >> y >> z;
        cout << sum[x + aaa][y + bbb][z + ccc] << endl;
    }
    return;
}

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

    int t = 1;
    //cin >> t;

    while (t--) {
        solve();
    }

    return  0;

}

详细

Test #1:

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

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

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

input:

1 1
?
0 1 1

output:

0

result:

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