QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#719095#9536. Athlete Welcome CeremonyCodeChild#WA 1ms7932kbC++203.0kb2024-11-06 22:28:422024-11-06 22:28:42

Judging History

This is the latest submission verdict.

  • [2024-11-06 22:28:42]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 7932kb
  • [2024-11-06 22:28:42]
  • Submitted

answer

#include <iostream>
#include <cstring>
#include <queue>
#include <map>
#include <cstdio>
#include <unordered_map>
#include <deque>
#include <iomanip>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stack>
#include <set>
#include <array>
#include <bitset>
#include <limits.h>
#include <numeric>
#define x first
#define y second

using namespace std;
typedef  long long LL;
typedef long long ll  ; 
typedef pair<int,int> PII;
typedef pair<int,LL> PIL;
typedef pair<int ,PII> PIII ;
typedef pair<int, pair<PII ,int > > PIIII;
typedef pair<LL , LL> PLL ; 
typedef pair<LL ,int > PLI ;
typedef pair<int,char > PIC ; 
typedef unsigned long long ULL ;
 
const int N = 300+10,M = 4e5+10  ;
const LL mod = 1e9+7 , INF = 1e18+10;
const int inf =  1e8 ; 
const double eps = 1e-7 ;
const ULL  P=  131 ;
LL n , m  , k   ;


LL a[N][N][N] ;  

void solve( ) {
	cin >> n >> k ;
	string s ; cin >> s; 
	vector<int> cnt( n + 1 ) ;
	s = " " + s ;
	for(int i = 1 ; i <= n ; ++ i ) cnt[i] = cnt[i-1] +( s[i] == '?' ) ;
	vector< vector< array<LL,3> >> f( n+1 , vector<array<LL,3>>( n+1 , array<LL,3>{ 0 , 0 ,0  }   )   ) ; 
	if( s[1] == '?' ) {
		f[1][0][0] = f[0][1][1] = f[0][0][2] = 1 ;
	}else {
		f[0][0][ s[1] - 'a' ] = 1 ;
	}
	for(int i = 2 ; i <= n ; ++ i ) {
		vector< vector< array<LL,3> >> g( n+1 , vector<array<LL,3>>( n+1 , array<LL,3>{ 0 , 0 ,0  }   )   ) ; 
		if( s[i] == '?' ) {
			for(int j = 0 ; j <= cnt[i-1] ; ++ j ) {
				for(int k = 0 ; k + j <= cnt[i-1] ; ++ k ) {
					int t = cnt[i-1] - j - k ;
					for(int c = 0 ; c < 3 ; ++ c ) {
						if( j + 1 <= cnt[i]  && c != 0)
							g[j+1][k][0] += f[j][k][c] , g[j+1][k][0] %= mod ;
						if( k + 1 <= cnt[i] && c != 1 )
							g[j][k+1][1] += f[j][k][c] ,  g[j][k+1][1] %= mod ;
						if( t + 1 <= cnt[i] && c != 2 )
							g[j][k][2] += f[j][k][c] , g[j][k][2] %= mod ;
					}
				}
			}
		}else {
			for(int j = 0 ; j <= cnt[i-1] ; ++ j ) {
				for(int k = 0 ; j + k <= cnt[i-1] ; ++ k ) {
					for(int c = 0 ; c < 3 ; ++ c ) {
						if( c != s[i] - 'a' ){
							g[j][k][s[i] -'a'] += f[j][k][c] ,  g[j][k][s[i] -'a'] %= mod ;
						}
					}
				}
			}
		}
		swap( f , g );  
	}
	for(int i = 0 ; i <= cnt[n] ; ++ i ) {
		for(int j = 0 ; j + i <= cnt[n] ; ++ j ) {
			a[i+j][i][j] = f[i][j][0] + f[i][j][1] + f[i][j][2] ;
			a[i+j][i][j] %= mod ;
		}
	}
	for(int c = 0 ; c <= cnt[n] ; ++ c ) {
		for(int i = 0 ; i <= cnt[n] ;++ i)
			for(int j = 0 ; j <= cnt[n] ; ++ j ){
				if( i ) a[c][i][j] += a[c][i-1][j] ;
				if( j ) a[c][i][j] += a[c][i][j-1];
				if( i && j ) a[c][i][j] -= a[c][i-1][j-1];
				a[c][i][j] %= mod ;
			}
	}
	
	while( k -- ) {
		int x, y , z ;
		cin >> x >> y >> z ;
		LL ans = 0 ;
		for(int i = 0 ; i <= z && i <= cnt[n] ; ++ i )
			ans += a[cnt[n] - i ][x][y] , ans %= mod;
		cout << (ans + mod ) % mod << '\n' ; 
	}
	
	
} 	
 
 
 
int main(){ 	
	ios::sync_with_stdio(false);
	cin.tie( 0 ) ; cout.tie(0) ;
	int T = 1 ;
	while(T-- ){	
		solve() ;  
   	}        
 	return  0 ;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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: 0ms
memory: 3792kb

input:

1 1
?
0 1 1

output:

2

result:

ok single line: '2'

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 3840kb

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
0
1
0
0
0
0
0
1

result:

wrong answer 3rd lines differ - expected: '1', found: '0'