/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 24ms 15.633 MiB
#2 Accepted 23ms 15.719 MiB
#3 Accepted 25ms 15.797 MiB
#4 Accepted 25ms 15.73 MiB
#5 Accepted 25ms 15.609 MiB
#6 Accepted 25ms 15.707 MiB
#7 Accepted 25ms 15.715 MiB
#8 Accepted 25ms 15.715 MiB
#9 Accepted 25ms 15.633 MiB
#10 Accepted 25ms 15.812 MiB
#11 Accepted 24ms 15.824 MiB
#12 Accepted 24ms 15.637 MiB
#13 Accepted 25ms 15.715 MiB
#14 Accepted 25ms 15.691 MiB
#15 Accepted 25ms 15.621 MiB
#16 Accepted 91ms 15.656 MiB
#17 Accepted 91ms 16.57 MiB
#18 Accepted 96ms 17.34 MiB
#19 Accepted 94ms 17.332 MiB
#20 Accepted 96ms 17.336 MiB
#21 Accepted 92ms 16.445 MiB

Code

#include <bits/stdc++.h>
//#define ll long long int

using namespace std;
typedef long long int ll;
priority_queue<int, vector<int>, greater<int>> pq;
const ll md = 1e9 + 7;
const ll md1 = 998244353;
map<ll, vector<ll>> tree;
//map<ll, int> mp;
ll dp[2000001];
ll mp(ll x,ll y,ll p){
	ll res=1;
	x=x%p;
	while(y>0){
		if(y&1)res=((res)%p*x%p)%p;
		y=y>>1;
		x=(x%p*x%p)%p;
	}
	return res;

}
ll ncr(ll n,ll r){
ll x=dp[n];
ll y=((dp[n-r])%md*(dp[r]%md))%md;
x=((x%md)*(mp(y,md-2,md)%md))%md;
return x;

}
ll power(ll base,ll pw){
ll res=1;
while(pw>0){
    if(pw%2==0){
       base=((base%md)*(base%md))%md;
        pw/=2;
    }
    else{
        res=((res%md)*(base)%md)%md;
        pw--;
    }
}
return res;

}
void sufi() {
ll n,k;
cin>>n>>k;
ll ara[n+1];
ll cnt1=0;
ll cnt2=0;
for(int i=1;i<=n;i++){
    cin>>ara[i];
    if(ara[i]==1)cnt1++;
    else cnt2++;
}
if(k==0){
    ll ans=0;
    for(ll i=0;i<=n;i++)
    ans=((ans%md)+ncr(n,i)%md)%md;
    cout<<ans-1<<endl;
    return ;
}
if(k>cnt1){
cout<<"0"<<endl;
return;
}
if(k==cnt1&&k==n){
    cout<<"0"<<endl;
return;
}
ll ans=0;
for(ll i=0;i<=cnt2;i++){
    ans=((ans%md)+(ncr(cnt2,i)%md))%md;
}
//cout<<ans<<endl;
ll sum=0;
for(ll i=k;i<=cnt1;i++){
    sum=(sum%md)+(ncr(cnt1,i)%md)%md;
}
sum=(sum%md*ans%md)%md;
sum=(sum-1+md)%md;

cout<<sum<<endl;

}
int main() {
    int t;
cin>>t;
dp[1]=1;
dp[0]=1;
for(ll i=2;i<=2000000;i++){
    dp[i]=((i%md)*(dp[i-1]%md))%md;
}
    while (t--) {
        sufi();
       //tree.clear();
        //mp.clear();
    }
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1094 Number of ways (Hard version)
Language
C++20 (G++ 13.2.0)
Submit At
2024-09-05 18:48:16
Judged At
2024-11-11 02:57:25
Judged By
Score
100
Total Time
96ms
Peak Memory
17.34 MiB