QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#702363 | #9536. Athlete Welcome Ceremony | ucup-team3661# | RE | 39ms | 642804kb | C++20 | 2.0kb | 2024-11-02 15:50:36 | 2024-11-02 15:50:37 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9+7;
void add(ll &a , ll b){
a += b;
a %= mod;
}
ll dp[301][301][301][3];
int main(){
int N; cin >> N;
int Q; cin >> Q;
string S; cin >> S;
for(int i = 0; i < 301; i++){
for(int j = 0; j < 301; j++){
for(int k = 0; k < 301; k++){
for(int l = 0; l < 3; l++){
dp[i][j][k][l] = 0;
}
}
}
}
if(S[0] == '?'){
dp[0][1][0][0] = 1;
dp[0][0][1][1] = 1;
dp[0][0][0][2] = 1;
}
else{
if(S[0] == 'a')dp[0][1][0][0] = 1;
if(S[0] == 'b')dp[0][0][1][1] = 1;
if(S[0] == 'c')dp[0][0][0][2] = 1;
}
for(int i = 1; i < N; i++){
for(int j = 0; j <= N; j++){
for(int k = 0; k <= N; k++){
for(int pre = 0; pre < 3; pre++){
if(S[i] == '?'){
if(j-1 >= 0 && pre != 0)add(dp[i][j][k][0] , dp[i-1][j-1][k][pre]);
if(k-1 >= 0 && pre != 1)add(dp[i][j][k][1] , dp[i-1][j][k-1][pre]);
if(pre != 2)add(dp[i][j][k][2] , dp[i-1][j][k][pre]);
}
else{
ll d = S[i] - 'a';
if(d == pre)continue;
if(d == 0){
if(j-1 >= 0)add(dp[i][j][k][0] , dp[i-1][j-1][k][pre]);
}
if(d == 1){
if(k-1 >= 0)add(dp[i][j][k][1] , dp[i-1][j][k-1][pre]);
}
if(d == 2){
add(dp[i][j][k][2] , dp[i-1][j][k][pre]);
}
}
}
}
}
}
vector<vector<ll>> sum(N+2 , vector<ll>(N+2));
for(int i = 0; i <= N; i++){
for(int j = 0; j <= N; j++){
add(sum[i][j+1] , sum[i][j]);
for(int k = 0; k < 3; k++)add(sum[i][j+1] , dp[N-1][i][j][k]);
}
}
int ba = 0, bb = 0, bc = 0;
for(int i = 0; i < N; i++){
if(S[i] == 'a')ba++;
if(S[i] == 'b')bb++;
if(S[i] == 'c')bc++;
}
while(Q--){
int A,B,C; cin >> A >> B >> C;
A += ba;
B += bb;
C += bc;
ll ans = 0;
for(int a = 0; a <= A; a++){
if(B+1 <= N-a-C)continue;
add(ans , sum[a][min(B+1,N+1)]);
add(ans , mod - sum[a][max(0 , N-a-C)]);
}
cout << ans << '\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 31ms
memory: 642724kb
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: 36ms
memory: 642776kb
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: 39ms
memory: 642772kb
input:
1 1 ? 0 1 1
output:
2
result:
ok single line: '2'
Test #4:
score: 0
Accepted
time: 24ms
memory: 642716kb
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: 24ms
memory: 642780kb
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: 19ms
memory: 642804kb
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
Runtime Error
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 497244 34272000 17637520