/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 6ms 3.523 MiB
#2 Accepted 5ms 3.57 MiB
#3 Accepted 6ms 3.512 MiB
#4 Accepted 6ms 3.551 MiB
#5 Accepted 6ms 3.586 MiB
#6 Accepted 10ms 3.52 MiB
#7 Accepted 12ms 3.609 MiB
#8 Accepted 15ms 3.52 MiB
#9 Accepted 16ms 3.516 MiB
#10 Accepted 16ms 3.586 MiB
#11 Accepted 9ms 3.52 MiB
#12 Accepted 9ms 3.52 MiB
#13 Accepted 13ms 3.562 MiB
#14 Accepted 14ms 3.406 MiB
#15 Accepted 14ms 3.52 MiB

Code

#include <bits/stdc++.h>
#define nl '\n'
#define ll long long
#define all(c) c.begin(),c.end()
#define print(c) for(auto e : c) cout << e << " "; cout << nl
using namespace std;
const ll N = 2E5, MOD = 1E9 + 7;
ll fact[N + 1], factInv[N + 1];
ll Pow(ll a, ll b) // O(log b)
{
    ll ans = 1 % MOD;
    a %= MOD;
    if (a < 0) a += MOD;
    while (b) 
    {
        if (b & 1) ans = (ans * a) % MOD;
        a = (a * a) % MOD;
        b >>= 1;
    }
    return ans;
}
void preCalc()
{
    fact[0] = fact[1] = 1;
    for (ll i = 2; i <= N; i++)
    {
        fact[i] = 1ll * (fact[i - 1] * i) % MOD;
    }
    
    factInv[N] = Pow(fact[N], MOD-2);
    for (ll i = N-1; i >= 0; i--)
    {
        factInv[i] = (factInv[i + 1] * (i + 1)) % MOD;
    }
}
ll nCr(ll n, ll r)
{
    if(r < 0 || n < 0 || r > n) return 0;
    return ((fact[n] * factInv[r]) % MOD) * factInv[n - r] % MOD;
}
ll nPr(ll n, ll r)
{
    return (fact[n] * factInv[n - r]) % MOD;
}
void solve()
{
    int n, k; cin >> n >> k;
    vector<int> a(n);
    for(auto &e : a) cin >> e;

    ll sum = 0, zero = 0;
    for(auto e : a) 
    {
        if(e == 1) sum++;
        else zero++;
    }

    ll ans = 0;
    for (ll i = k; i < sum; i++)
    {
        // cout << ans << nl;
        ans += nCr(sum, sum - i);
        ans %= MOD;
    }

    ans *= Pow(2, zero);
    ans %= MOD;

    if(sum >= k) ans += nCr(sum, 0) * (Pow(2, zero) - 1);
    ans %= MOD;

    cout << ans << nl;
}
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);

    preCalc();

    int t; cin >> t;
    while (t--)
    {
        solve();
    }
    

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1093 E1.Number of Ways (Easy version)
Language
C++17 (G++ 13.2.0)
Submit At
2025-08-08 10:17:58
Judged At
2025-08-08 10:17:58
Judged By
Score
100
Total Time
16ms
Peak Memory
3.609 MiB