QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#713631#9536. Athlete Welcome Ceremonycaojc#WA 1ms5876kbC++203.6kb2024-11-05 20:07:092024-11-05 20:07:10

Judging History

This is the latest submission verdict.

  • [2024-11-05 20:07:10]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 5876kb
  • [2024-11-05 20:07:09]
  • Submitted

answer

#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
#define ll long long 
#define pb push_back

#define db(args...){\
    string _s = #args; replace(_s.begin(), _s.end(), ',', ' ');\
    stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cout << '\n';}
void err(istream_iterator<string> it){}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << ' ';
    err(++it, args...);
}

typedef long long LL;
typedef pair<LL, LL> PII;

const int N = 305;
const int MOD = 1e9 + 7;
LL f[N][N][N][3], sum[N][N][N];
void add(LL &a, LL b) {
    a = (a + b) % MOD;
}

void solve() {
    int n, q;
    cin >> n >> q;
    string s; cin >> s;
    s = '#' + s;

    int ques = 0;
    for (int i = 1; i <= n; i++) ques += s[i] == '?';

    for (int i = 1; i <= n; i++) {
        for (int a = 0; a <= ques; a++) {
            for (int b = 0; a + b <= ques; b++) {
                for (int j = 0; j < 3; j++) {
                    LL &now = f[i][a][b][j];
                    if (s[i] != '?') {
                        if (s[i] - 'a' != j) continue;
                        if (i == 1) {
                            if (a == 0 && b == 0) now = 1;
                        }
                        else {
                            for (int k = 0; k < 3; k++) {
                                if (k == j) continue;
                                add(now, f[i - 1][a][b][k]);
                            }
                        }
                    }
                    else {
                        if (i == 1) {
                            if (j == 0 && a == 1 && b == 0) now = 1;
                            if (j == 1 && a == 0 && b == 1) now = 1;
                            if (j == 2 && a == 0 && b == 0) now = 1;
                        }
                        else {
                            for (int k = 0; k < 3; k++) {
                                if (k == j) continue;
                                if (j == 0 && a >= 1) add(now, f[i - 1][a - 1][b][k]);
                                if (j == 1 && b >= 1) add(now, f[i - 1][a][b - 1][k]);
                                if (j == 2) add(now, f[i - 1][a][b][k]); 
                            }
                        }
                    }
                }
            }
        }
    }
    
    
    for (int a = 0; a <= ques; a++) {
        for (int b = 0; a + b <= ques; b++) {
            int c = ques - a - b;
            for (int j = 0; j < 3; j++) {
                add(sum[a + 1][b + 1][c + 1], f[n][a][b][j]);
            }
        }
    }

    // 3d pre sum
    for (int a = 1; a <= ques + 1; a++) {
        for (int b = 1; b <= ques + 1; b++) {
            for (int c = 1; c <= ques + 1; c++) {
                LL &now = sum[a][b][c];
                now += sum[a - 1][b][c];
                now += sum[a][b - 1][c];
                now += sum[a][b][c - 1];
                now += -sum[a - 1][b - 1][c];
                now += -sum[a - 1][b][c - 1];
                now += -sum[a][b - 1][c - 1];
                now += sum[a - 1][b - 1][c - 1];
                now = (now % MOD + MOD) % MOD;
            }
        }
    }

    while (q--) {
        int x, y, z;
        cin >> x >> y >> z;
        cout << sum[x + 1][y + 1][z + 1] << "\n";
    }
}
signed main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int t = 1;
    // cin >> t;
    while (t--) solve();
    return 0;
}

/*
g++ b.cpp -std=c++20 -o b && ./b < in.txt > out.txt
*/

詳細信息

Test #1:

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

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

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

input:

1 1
?
0 1 1

output:

2

result:

ok single line: '2'

Test #4:

score: -100
Wrong Answer
time: 1ms
memory: 5688kb

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'