/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 10ms 2.277 MiB
#2 Accepted 11ms 2.289 MiB
#3 Accepted 14ms 2.281 MiB
#4 Accepted 12ms 2.277 MiB
#5 Accepted 14ms 2.324 MiB
#6 Accepted 15ms 2.277 MiB
#7 Accepted 18ms 2.391 MiB
#8 Accepted 14ms 2.281 MiB
#9 Accepted 11ms 2.309 MiB
#10 Accepted 15ms 2.395 MiB
#11 Accepted 11ms 2.5 MiB
#12 Accepted 14ms 2.277 MiB
#13 Accepted 12ms 2.219 MiB
#14 Accepted 14ms 2.43 MiB
#15 Accepted 18ms 2.262 MiB

Code

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int N = 500010;

int mod = 1e9 + 7;

int power(int a, int b, int M)
{
    if (!b)
        return 1;
    int temp = power(a, b / 2, M);
    temp = 1LL * temp * temp % M;
    if (b % 2)
        temp = 1LL * temp * a % M;
    return temp;
}

int fact[N];
void pre()
{
    fact[0] = 1;
    for (int i = 1; i < N; i++)
    {
        fact[i] = 1LL * fact[i - 1] * i % mod;
    }
}

ll npr(ll n, ll r)
{
    if (r > n)
        return 0;
    ll res = fact[n];
    res = (res * power(fact[n - r], mod - 2, mod)) % mod;
    return res;
}
int ncr(int n, int r)
{
    if (n < r)
        return 0;
    assert(n >= 0 && n < N && r >= 0 && r < N);
    int ans = fact[n];
    ans = 1LL * ans * power(fact[n - r], mod - 2, mod) % mod;
    ans = 1LL * ans * power(fact[r], mod - 2, mod) % mod;
    if (ans < 0)
        ans += mod;
    assert(ans >= 0 && ans < mod);
    return ans;
}
int main()
{
    pre();
    int t, n, x,k;
    cin >> t;
    while (t--)
    {
        cin >> n>>k;
        ll sum = 0, ze;
        ll on = ze = 0;
        
        for (int i = 0; i < n; i++)
        {
            cin >> x;

            if (x == 1)
            {
                sum++;
                on++;
            }
            else
            {
                ze++;
            }
        }

        ll baki=sum-k;
        if(baki<0)
        {
            cout<<0<<endl;
            continue;
        }
        else
        {
            ll x=power(2,ze,mod);
            x--;
            ll ans=x;
            for(ll i=1;i<=baki;i++)
            {
                ll z=ncr(on,i);
                ans+=z;
                ans%=mod;
                ll pp=(1LL*x*z)%mod;
                ans+=pp;
                ans%=mod;
            }
            cout<<ans<<endl;
        }


    }
}

Information

Submit By
Type
Submission
Problem
P1093 Number of Ways (Easy version)
Language
C++17 (G++ 13.2.0)
Submit At
2024-09-06 14:59:07
Judged At
2024-09-06 14:59:07
Judged By
Score
100
Total Time
18ms
Peak Memory
2.5 MiB