记录编号 584694 评测结果 AAAAAAAAAAAAAAAA
题目名称 魔药 最终得分 100
用户昵称 Gravatar┭┮﹏┭┮ 是否通过 通过
代码语言 C++ 运行时间 0.111 s
提交时间 2023-11-14 17:11:14 内存使用 7.16 MiB
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long N = 1e6+10,mod = 1e9+7;
int n,m,k,p = 1e9+7;
ll s[N] = {1,1},ans;
char c[N];
ll pow(ll x,int y){
    if(y == 0)return 1;
    ll ans = pow(x,y/2);
    if(y % 2)return (ans * ans) % mod * x % mod;
    else return (ans * ans) % mod;
}
ll C(int x,int y){
    return (s[x] * pow(s[x-y],p-2)) % mod * pow(s[y],p-2) % mod;
}
int main(){
    freopen("sleeping.in","r",stdin);
    freopen("sleeping.out","w",stdout);
    scanf("%lld%lld%s",&n,&m,c+1);
    for(int i = 1;i <= n;i++)if(c[i] == '1')k++;
    for(int i = 2;i <= n;i++)s[i] = s[i-1] * i % mod;
    if(m > n){
        printf("0 %lld\n",C(n,k));
        return 0;
    }
    if(m % 2 == 0)ans = 2 * C(k-1,k-m/2) * C(n-k-1,k-m/2) % mod;
    else ans = (C(k-1,k-m/2) * C(n-k-1,n-k-m/2-1) % mod + (C(k-1,k-m/2-1) * C(n-k-1,n-k-m/2))) % mod;
//    cout<<ans<<endl;
    long long s = C(n,k) - ans;
    if(s < 0)s += mod;
    printf("%lld %lld\n",ans,s);
    
    return 0;
    
}