QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#737594#9536. Athlete Welcome Ceremonyucup-team1412WA 4ms26400kbC++143.1kb2024-11-12 16:22:442024-11-12 16:22:44

Judging History

This is the latest submission verdict.

  • [2024-11-12 16:22:44]
  • Judged
  • Verdict: WA
  • Time: 4ms
  • Memory: 26400kb
  • [2024-11-12 16:22:44]
  • Submitted

answer

//https://contest.ucup.ac/contest/1821/problem/9536?v=1
//f[i][x][y][p] : 考虑前i个字符,使用j个a,k个b,并且最后一个字符是p
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll maxn = 305;
ll n , q;
string c, s;
ll f[maxn][maxn][maxn][3];
ll g[maxn][maxn][maxn];
ll cnt[3];
const ll mod = 1e9 + 7;
signed main(){
    cin >> n >> q;
    cin >> c;
    s = "0";
    s += c;

    for(ll i = 1 ; i <= n;i++){
        if(s[i]!='?')cnt[ (ll)(s[i] - 'a') ]++; 
    }


    if(s[1] == '?'){
        f[1][2][1][0] = 1;
        f[1][1][2][1] = 1;
        f[1][1][1][2] = 1;

    }
    else{
        if(s[1] == 'a')f[1][2][1][0] = 1;
        if(s[1] == 'b')f[1][1][2][1] = 1;
        if(s[1] == 'c')f[1][1][1][2] = 1;
    }

    for(ll i = 2; i <= n ;i ++){
        for(ll x = 1 ; x <= i + 1 ; x++){
            for(ll y = 1 ; x + y <= i + 2; y++ ){
                // cout <<  "fdassdas" << endl;
                ll z = i + 3 - x - y;

                if(s[i] != '?'){
                    if(s[i] == 'a' && x >= 1){
                        //f[1][2][1][0]
                        f[i][x][y][0] = ( f[i - 1][x - 1][y][1] + f[i - 1][x - 1][y][2]) % mod ;
                    }
                    else if ( s[i] == 'b' && y >= 1 ){
                        f[i][x][y][1] = (f[i - 1][x][y - 1][0] + f[i - 1][x][y - 1][2])% mod ;
                    }
                    else if ( s[i] == 'c' && z >= 1 ){
                        f[i][x][y][2] = (f[i - 1][x][y][0] + f[i - 1][x][y][1] ) % mod;
                    }
                }
                else{
                    if(s[i - 1] != 'a' && x >= 1  ){//can select a
                        f[i][x][y][0] = (  f[i - 1][x - 1][y][1] + f[i - 1][x - 1][y][2]) % mod;
                    }
                    if(s[i - 1] != 'b' && y >= 1){//can select b
                        f[i][x][y][1] = (f[i - 1][x][y - 1][0]  + f[i - 1][x][y - 1][2]) % mod;
                    }
                    if(s[i - 1] != 'c' && z >= 1){//can select c
                        f[i][x][y][2] = (f[i - 1][x][y][0] + f[i - 1][x][y][1] ) % mod;
                    }
                }


            }
        }
    }


    // cout << f[6][3][3][2] << endl;
    for(ll x = 1 ; x <= n + 1; x++){
        for(ll y = 1 ;y <= n + 1; y++){
            for(ll z = 1 ; z <= n + 1 ; z++){

                ll res = 0;
                for(ll  i = 0 ; i <= 2 ; i++){
                    res = ( res + f[n][x][y][i])% mod;
                }
                // cout << res << endl;

                g[x][y][z] = (g[x-1][y][z] + g[x][y-1][z] + g[x][y][z-1] - g[x-1][y-1][z]-g[x-1][y][z-1]-g[x][y-1][z-1] + g[x-1][y-1][z-1] )%mod;
                if(x + y + z == n + 3){
                    g[x][y][z] = (g[x][y][z] + res) % mod;
                }
                // cout << g[x][y][z] << endl;
            }



        }
    }

    while(q--){
        ll x,y,z;
        cin >> x >> y >> z;
        cout << g[x + 1 + cnt[0] ][y + 1 + cnt[1] ][z + 1 + cnt[2] ]<< endl;
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 16140kb

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: 3ms
memory: 16068kb

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

input:

1 1
?
0 1 1

output:

2

result:

ok single line: '2'

Test #4:

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

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: -100
Wrong Answer
time: 4ms
memory: 24404kb

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:

0
0
11
16
11
16
0
0
0
0

result:

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