/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 11ms 2.293 MiB
#2 Accepted 11ms 2.418 MiB
#3 Accepted 13ms 2.289 MiB
#4 Accepted 13ms 2.289 MiB
#5 Accepted 15ms 2.266 MiB
#6 Accepted 17ms 2.434 MiB
#7 Accepted 20ms 2.223 MiB
#8 Accepted 16ms 2.25 MiB
#9 Accepted 12ms 2.391 MiB
#10 Accepted 16ms 2.422 MiB
#11 Accepted 12ms 2.312 MiB
#12 Accepted 16ms 2.305 MiB
#13 Accepted 13ms 2.398 MiB
#14 Accepted 16ms 2.23 MiB
#15 Accepted 20ms 2.332 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-11-11 02:55:50
Judged By
Score
100
Total Time
20ms
Peak Memory
2.434 MiB