/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 10ms 3.484 MiB
#2 Accepted 10ms 3.52 MiB
#3 Accepted 10ms 3.52 MiB
#4 Accepted 10ms 3.512 MiB
#5 Accepted 31ms 3.496 MiB
#6 Accepted 17ms 3.527 MiB
#7 Accepted 17ms 3.613 MiB
#8 Accepted 17ms 3.391 MiB
#9 Accepted 17ms 3.496 MiB
#10 Accepted 16ms 3.633 MiB
#11 Accepted 11ms 3.516 MiB
#12 Accepted 11ms 3.52 MiB
#13 Accepted 15ms 3.512 MiB
#14 Accepted 15ms 3.605 MiB
#15 Accepted 15ms 3.449 MiB
#16 Accepted 39ms 3.547 MiB
#17 Accepted 25ms 3.887 MiB
#18 Accepted 27ms 4.336 MiB
#19 Accepted 28ms 4.27 MiB
#20 Accepted 22ms 4.344 MiB
#21 Accepted 26ms 3.953 MiB

Code

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
const int Max=2e5+10;
ll mod = 1e9+7;
#define printp(v) for(auto e:v) cout<<e.first<<" "<<e.second<<endl;

ll fact[Max+1] , factInv[Max+1];

// modular inverse b = (b)^-1 = Pow(b,m-2);

long long Pow(ll a,ll b){
    ll ans = 1;
    while(b>0){
        if(b&1) ans=(ans*a)%mod;
        b>>=1;
        a=(a*a)%mod;
    }
    return ans;
}

// void prec(){
//     fact[0] = 1;
//     for(ll i = 1;i <= N; i++){
//         fact[i] = (fact[i-1] * i) % mod;
//     }
//     factinv[N] = modPow(factInv[N],mod-2); // fact N! to start
//     for(ll i = N-1; i>=0; i--){
//         factinv[i]  = (factinv[i+1] * (i+1)) % mod ;
//     }
// }

// ll nCr(ll n, ll r){
//     if(r > n || r < 0 || n<0) return 0;
//     return ((fact[n] * factinv[r]) % mod * factinv[n-r]) % mod;
// }

// ll nPr(ll n, ll r){
//     if(n < r || r < 0 || n < 0) return 0;
//     return ((fact[n] * factinv[n-r])) % mod;
// }
void build_fact() {
    fact[0] = 1;
    for(int i = 1; i < Max; i++)
    {
        fact[i] = 1LL * fact[i - 1] * i % mod;
    }
    factInv[Max - 1] = Pow(fact[Max - 1], mod - 2);
    for(int i = Max - 2; i >= 0; i--)
    {
        factInv[i] = 1LL * factInv[i + 1] * (i + 1) % mod;
    }
    return;
}

ll nCr_mod(int n, int r) {
    if(n < r or n < 0 or r < 0) return 0;
    return 1LL * fact[n] * factInv[r] % mod * factInv[n - r] % mod;
}

int nPr_mod(int n, int r) { // nPr = nCr * r! 
    if(n < r or n < 0 or r < 0) return 0;
    return (1LL * nCr_mod(n, r) * fact[r]) % mod;
}
void solve() {
    ll ans = 0;
    ll n,k;cin >> n>>k;
    vector<int>p(n);
    ll one = 0;
    ll zero = 0;
    for(int i = 0; i < n ; i++){
        cin >> p[i];
        if(p[i] == 0) zero++;
        else one++;
    }
    if(one < k){
        cout<<0 << endl;return;
    }
    ll nts = Pow(2,zero);
    for(int i = k; i < one ; i++){
        ans += (nCr_mod(one,one-i)*nts);
        ans %= mod;
    }
    ll mt = nts-1;
    ans += nCr_mod(one,0)*mt;
    ans %= mod;
    cout << ans << endl; 
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    build_fact();
    int t = 1; cin >> t;
    while(t--){
        solve();
    }
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1094 E2. Number of ways (Hard version)
Language
C++17 (G++ 13.2.0)
Submit At
2025-08-08 10:19:05
Judged At
2025-08-08 10:19:05
Judged By
Score
100
Total Time
39ms
Peak Memory
4.344 MiB