QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#722135#9536. Athlete Welcome Ceremonywangshengzhe#WA 0ms24116kbC++143.5kb2024-11-07 17:57:572024-11-07 17:57:58

Judging History

This is the latest submission verdict.

  • [2024-11-07 17:57:58]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 24116kb
  • [2024-11-07 17:57:57]
  • Submitted

answer

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<unordered_map>
#include<stack>
using namespace std;
#define int long long
#define scanf scanf_s
typedef pair<int, int> PII;

const double ef = 1e-12;
const int INF = 0x3f3f3f3f3f3f3f3f;
#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;

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][2] = 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 + 1][bb + 1][cc + 1] = (dp[aa][bb][cc][0] + dp[aa][bb][cc][1] + dp[aa][bb][cc][2]) % mod;
                }
            }
        }
    }
    n++;
    rep(i, 1, n)
        rep(k, 1, n)
        rep(j, 1, n)
        sum[i][k][j] = (sum[i][k][j] + sum[i - 1][k][j]) % mod;

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

    rep(i, 1, n)
        rep(k, 1, n)
        rep(j, 1, n)
        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 + 1][y + bbb + 1][z + ccc + 1] % mod << endl;
    }
    return;
}

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

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

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

    return  0;

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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

input:

1 1
?
0 1 1

output:

0

result:

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