/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 12ms 2.34 MiB
#2 Accepted 12ms 2.312 MiB
#3 Accepted 14ms 2.332 MiB
#4 Accepted 14ms 2.312 MiB
#5 Accepted 16ms 2.438 MiB
#6 Accepted 17ms 2.434 MiB
#7 Accepted 21ms 2.434 MiB
#8 Accepted 18ms 2.434 MiB
#9 Accepted 14ms 2.344 MiB
#10 Accepted 16ms 2.43 MiB
#11 Accepted 14ms 2.438 MiB
#12 Accepted 17ms 2.434 MiB
#13 Accepted 14ms 2.391 MiB
#14 Accepted 17ms 2.238 MiB
#15 Accepted 21ms 2.434 MiB
#16 Accepted 212ms 2.207 MiB
#17 Accepted 193ms 2.434 MiB
#18 Accepted 226ms 2.43 MiB
#19 Accepted 373ms 2.43 MiB
#20 Accepted 71ms 2.438 MiB
#21 Accepted 203ms 2.43 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
P1094 Number of ways (Hard version)
Language
C++17 (G++ 13.2.0)
Submit At
2024-09-06 14:59:42
Judged At
2024-11-11 02:55:50
Judged By
Score
100
Total Time
373ms
Peak Memory
2.438 MiB