/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 496.0 KiB
#2 Wrong Answer 2ms 376.0 KiB
#3 Wrong Answer 3ms 772.0 KiB
#4 Wrong Answer 3ms 584.0 KiB
#5 Accepted 3ms 604.0 KiB
#6 Wrong Answer 3ms 584.0 KiB
#7 Accepted 3ms 616.0 KiB
#8 Accepted 3ms 744.0 KiB
#9 Wrong Answer 3ms 488.0 KiB
#10 Wrong Answer 3ms 616.0 KiB
#11 Accepted 3ms 540.0 KiB
#12 Wrong Answer 3ms 540.0 KiB
#13 Wrong Answer 3ms 628.0 KiB
#14 Wrong Answer 3ms 596.0 KiB
#15 Wrong Answer 3ms 616.0 KiB

Code

#include<bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>*/
typedef long long ll;
#define N 5001
#define lcm(a,b) ((a*b)/__gcd(a,b))
const ll mod=1e9+7;
        ll prime[N];
        vector<int>all_primes;
        ll prime_factors[N];
        void seive()
        {
            memset(prime,0,sizeof(prime));
            prime[0]=1;prime[1]=1;
            for(ll i=2;i*i<=N-1;i++)
            {
            if(prime[i]==0)
                {
                    for(ll j=i*i;j<N;j+=i)
                    {
                        prime[j]=1;
                    }
                }
            }
            for(int i=1;i<N;i++)
            {
                if(!prime[i])
                {
                    all_primes.push_back(i);
                }
            }
        }

        void spf()
        {
            for(ll i=1;i<N;i++)
            {
                prime_factors[i]=i;
            }

            for(ll i=2;i*i<=N-1;i++)
            {
                for(ll j=i*i;j<=N-1;j+=i)
                {
                    if(prime_factors[j]==j)
                        prime_factors[j]=i;
                }
            }
        }
//code starts here
ll binary_expo(ll base,ll power)
{
    ll ans=1;
    while(power>0)
    {
        if(power%2==1)
            ans=(ans*base)%mod;

        base=(base*base)%mod;
        power/=2;
    }
    return ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll fact[N];
    fact[0]=1;
    for(ll i=1;i<N;i++)
    {
        fact[i]=(i*fact[i-1])%mod;
    }
    int t;
    cin>>t;
    //t=1;
    while(t--)
    {
       int n,k,one=0,zero=0;
       cin>>n>>k;
       int a[n];
       for(int i=0;i<n;i++)
       {
           cin>>a[i];
           if(a[i]==1)
            one++;
           else
            zero++;
       }
       if(k>one)
       {
           cout<<"0\n";
           continue;
       }
       int x=one-k;
       ll ans=0,temp=0,temp2=0;
        for(int i=x;i>=0;i--)
        {
           ll y=fact[zero];
           ll u=fact[one];
           ll v=fact[one-i];
           v=(v*fact[i])%mod;
           ll p=(u*binary_expo(v,mod-2))%mod;

           if(zero>0 && i>0)
            temp2=(temp2+p)%mod;

           ll q=(p*fact[zero])%mod;

           if(i==0 && zero==0)
            continue;

           temp=(temp+q)%mod;
        }


        ans=(ans+temp+temp2)%mod;

       cout<<ans<<"\n";
    }
}

Information

Submit By
Type
Submission
Problem
P1093 Number of Ways (Easy version)
Contest
Brain Booster #5
Language
C++20 (G++ 13.2.0)
Submit At
2024-09-05 17:42:32
Judged At
2024-10-03 13:02:58
Judged By
Score
36
Total Time
3ms
Peak Memory
772.0 KiB