#include <cstdio>
#include <cstring>
const int mod = 1e9 + 7;
int n, p, q;
char sa[2005], sb[2005];
char tab[2005][6];
int dp[205][205][205];
int bino[2005][2005];
int f(int pos, int p, int q){
if(p < 0 || q < 0) return 0;
if(pos == n) return p == 0 && q == 0;
if(~dp[pos][p][q]) return dp[pos][p][q];
int ret = 0;
for (int i=0; i<5; i++) {
if(tab[pos][i] != '.'){
ret += f(pos+1,p - (sa[pos] == tab[pos][i]),q - (sb[pos] == tab[pos][i]));
ret %= mod;
}
}
return dp[pos][p][q] = ret;
}
void solve_sub2(){
int cnt_nomatch = 0;
int cnt_amatch = 0;
int cnt_bmatch = 0;
int cnt_abmatch = 0;
for (int i=0; i<n; i++) {
if(tab[i][sa[i] - 'a'] != '.' && tab[i][sb[i] - 'a'] != '.'){
cnt_abmatch++;
}
else if(tab[i][sa[i] - 'a'] != '.'){
cnt_amatch++;
}
else if(tab[i][sb[i] - 'a'] != '.'){
cnt_bmatch++;
}
else{
cnt_nomatch++;
}
}
for (int i=0; i<=n; i++) {
bino[i][0] = 1;
for (int j=1; j<=i; j++) {
bino[i][j] = bino[i-1][j] + bino[i-1][j-1];
bino[i][j] %= mod;
}
}
int ret = 0;
for (int i=0; i<=cnt_abmatch; i++) {
int p_req = p - i;
int q_req = q - i;
if(p_req < 0 || q_req < 0 || p_req > cnt_amatch || q_req > cnt_bmatch) continue;
long long t = 1ll * bino[cnt_amatch][p_req] * bino[cnt_bmatch][q_req] % mod;
t *= bino[cnt_abmatch][i];
ret += t;
ret %= mod;
}
for (int j=0; j<cnt_nomatch; j++) {
ret <<= 1;
ret %= mod;
}
printf("%d",ret);
}
void what_the_fuck(){
char str[10];
memset(dp,-1,sizeof(dp));
scanf("%d %d %d",&n,&p,&q);
for (int i=0; i<n; i++) {
scanf("%s",str);
sa[i] = str[0];
}
for (int i=0; i<n; i++) {
scanf("%s",str);
sb[i] = str[0];
}
for (int i=0; i<n; i++) {
scanf("%s",tab[i]);
}
if(n > 200){
solve_sub2();
return;
}
printf("%d",f(0,p,q));
}
int main(){
what_the_fuck();
puts("");
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
50456 KB |
Output is correct |
2 |
Correct |
0 ms |
50456 KB |
Output is correct |
3 |
Correct |
0 ms |
50456 KB |
Output is correct |
4 |
Correct |
4 ms |
50456 KB |
Output is correct |
5 |
Correct |
0 ms |
50456 KB |
Output is correct |
6 |
Correct |
0 ms |
50456 KB |
Output is correct |
7 |
Correct |
4 ms |
50456 KB |
Output is correct |
8 |
Correct |
3 ms |
50456 KB |
Output is correct |
9 |
Correct |
29 ms |
50456 KB |
Output is correct |
10 |
Correct |
73 ms |
50456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
50456 KB |
Output is correct |
2 |
Correct |
4 ms |
50456 KB |
Output is correct |
3 |
Incorrect |
4 ms |
50456 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
50456 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |