/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 16ms 15.648 MiB
#2 Accepted 16ms 15.574 MiB
#3 Wrong Answer 18ms 15.688 MiB
#4 Accepted 17ms 15.688 MiB
#5 Accepted 19ms 15.738 MiB
#6 Wrong Answer 19ms 15.812 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;
    cout<<ans<<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:45:40
Judged At
2024-11-11 02:57:29
Judged By
Score
7
Total Time
19ms
Peak Memory
15.812 MiB