/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 6ms 3.559 MiB
#2 Accepted 6ms 3.52 MiB
#3 Accepted 8ms 3.566 MiB
#4 Accepted 14ms 3.562 MiB
#5 Accepted 14ms 3.52 MiB
#6 Accepted 14ms 3.566 MiB
#7 Accepted 19ms 3.422 MiB
#8 Accepted 10ms 3.52 MiB
#9 Accepted 10ms 3.562 MiB
#10 Accepted 10ms 3.52 MiB
#11 Accepted 10ms 3.578 MiB
#12 Accepted 10ms 3.625 MiB
#13 Accepted 12ms 3.43 MiB
#14 Accepted 12ms 3.59 MiB
#15 Accepted 12ms 3.621 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(N, MOD-2);
    for (ll i = N-1; i >= 0; i--)
    {
        factInv[i] = (factInv[i + 1] * (i + 1)) % MOD;
    }
}
void build_fact()
{
    fact[0] = 1;
    for(int i = 1; i < N; i++)
    {
        fact[i] = 1LL * fact[i - 1] * i % MOD;
    }
    factInv[N - 1] = Pow(fact[N - 1], MOD - 2);
    for(int i = N - 2; i >= 0; i--)
    {
        factInv[i] = 1LL * factInv[i + 1] * (i + 1) % MOD;
    }
    return;
}
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();
    build_fact();

    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:13:41
Judged At
2025-08-08 10:13:41
Judged By
Score
100
Total Time
19ms
Peak Memory
3.625 MiB