This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <stdio.h>
#define N 2000
#define MD 1000000007
int vv[N + 1], ff[N + 1], gg[N + 1];
void init() {
int i;
ff[0] = gg[0] = 1;
for (i = 1; i <= N; i++) {
vv[i] = i == 1 ? 1 : (long long) vv[i - MD % i] * (MD / i + 1) % MD;
ff[i] = (long long) ff[i - 1] * i % MD;
gg[i] = (long long) gg[i - 1] * vv[i] % MD;
}
}
int choose(int n, int k) {
return (long long) ff[n] * gg[k] % MD * gg[n - k] % MD;
}
int main() {
static char s[8];
static int aa[N], bb[N], dp[N + 1], dq[N + 1];
int n, x, y, i, k, l, a, c, ans;
init();
scanf("%d%d%d", &n, &x, &y);
for (i = 0; i < n; i++) {
scanf("%s", s);
aa[i] = s[0] - 'a';
}
for (i = 0; i < n; i++) {
scanf("%s", s);
bb[i] = s[0] - 'a';
}
dp[0] = dq[0] = 1;
for (i = 0; i < n; i++) {
scanf("%s", s);
c = 0;
for (a = 0; a < 5; a++)
if (s[a] != '.')
c++;
if (aa[i] == bb[i])
for (k = n - 1; k >= 0; k--) {
dp[k + 1] = (dp[k + 1] + dp[k]) % MD;
dp[k] = (long long) dp[k] * (c - 1) % MD;
}
else
for (k = n - 1; k >= 0; k--) {
dq[k + 1] = (dq[k + 1] + dq[k]) % MD;
dq[k] = (long long) dq[k] * (c - 2) % MD;
}
}
ans = 0;
for (k = 0; k <= n && k <= x && k <= y; k++) {
l = x + y - k * 2;
if (l > n)
continue;
ans = (ans + (long long) dp[k] * dq[l] % MD * choose(l, x - k)) % MD;
}
printf("%d\n", ans);
return 0;
}
Compilation message (stderr)
multiple.c: In function 'main':
multiple.c:29:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
29 | scanf("%d%d%d", &n, &x, &y);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
multiple.c:31:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
31 | scanf("%s", s);
| ^~~~~~~~~~~~~~
multiple.c:35:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
35 | scanf("%s", s);
| ^~~~~~~~~~~~~~
multiple.c:40:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
40 | scanf("%s", s);
| ^~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |