/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 21ms 8.027 MiB
#2 Accepted 21ms 8.191 MiB
#3 Accepted 25ms 8.191 MiB
#4 Accepted 28ms 8.191 MiB
#5 Accepted 25ms 8.188 MiB
#6 Accepted 31ms 8.191 MiB
#7 Accepted 30ms 8.23 MiB
#8 Accepted 26ms 8.23 MiB
#9 Accepted 31ms 8.23 MiB
#10 Accepted 30ms 8.191 MiB
#11 Accepted 22ms 8.191 MiB
#12 Accepted 31ms 8.23 MiB
#13 Accepted 27ms 8.191 MiB
#14 Accepted 30ms 8.184 MiB
#15 Accepted 31ms 8.23 MiB

Code

#include <iostream>
#include <cstdio>
#include<list>
#include<iomanip>
#include<cmath>
#include<queue>
#include <functional>
#include<stdio.h>
#include<assert.h>
#include<stack>
#include<sstream>
#include <cstdlib>
#include<map>
#include<algorithm>
#include<set>
#include<utility>
#include<memory.h>
#include<string>
#include<vector>
#include<numeric>
#include <bitset>
using namespace std;
#define ll  long long
#define pb push_back
#define fi(ss) freopen (ss,"r",stdin)
#define fo(ss) freopen (ss,"w",stdout)
#define sz(v)               ((ll)((v).size()))
#define all(x)          (x).begin(),(x).end()
#define rep(i, v)       for(ll i=0;i<sz(v);i++)
#define lp(i,n) for(ll i = 0 ; i < n ; ++i)
#define lpab(i, a, b) for(ll i = a; i <= b; i++)
#define lpba(i, b, a) for(ll i = b; i >= a; i--)
#define hash ___hash
#define next ___next
#define prev ___prev
#define left ___left
#define time __time
typedef pair<ll, ll> pii;
#define F first
#define S second
#define MP make_pair
#define vi vector<ll>
#define vvi vector<vi>
#define vpii vector<pii>
#define mpii map<ll, ll> 
#define mpsi map<string, ll>
#define vs vector<string>
#define ld long double
#define vd vector<ld>
#define pie acos(-1)
const ll maxn = 4 * 100005;
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define txtio   freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define OO 1e18

ll mod = 1e9 + 7;

ll power(ll a, ll p, ll m)
{
	if (p == 0)
		return 1;
	ll sq = power(a, p / 2, m);
	sq %= m;
	sq *= sq;
	sq %= m;
	if (p % 2)
		sq *= a;
	sq %= m;
	return sq;
}

ll modInverse(int A, int M)
{
	return power(A, M - 2, M) % mod;
}

vi factorial(1e6 + 1);

ll fact(ll n)
{
	return factorial[n];
}

void calc_fact()
{
	factorial[0] = 1;
	ll num = 1;
	lpab(i, 1, 1e6)
	{
		num *= i;
		num %= mod;
		factorial[i] = num;
	}
}

ll comb(ll n, ll k)
{
	if (n == k || k == 0)
		return 1;
	ll n1 = fact(n), n2 = modInverse(fact(k), mod), n3 = modInverse(fact(n - k), mod);
	ll res = n1 * n2;
	res %= mod;
	res *= n3;
	return res % mod;
}

int main()
{
	fastio;
	ll t;
	calc_fact();
	cin >> t;
	while (t--)
	{
		ll n, k, sum = 0;
		cin >> n >> k;
		ll n0 = 0, n1 = 0;
		vi v(n);
		lp(i, n)
		{
			cin >> v[i];
			sum += v[i];
			if (v[i] == 0)
				n0++;
		}
		if (sum < k)
		{
			cout << 0 << endl;
			continue;
		}
		n1 = sum - k;
		ll ans = 0;
		ll b = 0;
		lpab(i, 0, n1)
		{
			b += comb(sum, i);
			b %= mod;
		}
		b %= mod;
		ll a = 0;
		lpab(i, 0, n0)
		{
			a += comb(n0, i);
			a %= mod;
		}
		ans += a * b;
		ans %= mod;
		ans--;
		if (ans < 0)
			ans += mod;
		ans %= mod;
		cout << ans << endl;
	}
	return 0;
}

Information

Submit By
Type
Submission
Problem
P1093 Number of Ways (Easy version)
Language
C++20 (G++ 13.2.0)
Submit At
2024-09-05 19:47:47
Judged At
2024-11-11 02:57:07
Judged By
Score
100
Total Time
31ms
Peak Memory
8.23 MiB