/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 3ms 2.07 MiB
#2 Accepted 3ms 2.027 MiB
#3 Accepted 5ms 2.07 MiB
#4 Accepted 5ms 2.082 MiB
#5 Accepted 6ms 2.008 MiB
#6 Accepted 8ms 2.043 MiB
#7 Accepted 10ms 1.988 MiB
#8 Accepted 7ms 2.07 MiB
#9 Accepted 4ms 2.07 MiB
#10 Accepted 7ms 1.949 MiB
#11 Accepted 4ms 1.934 MiB
#12 Accepted 8ms 2.035 MiB
#13 Accepted 5ms 2.027 MiB
#14 Accepted 7ms 1.965 MiB
#15 Accepted 11ms 2.027 MiB
#16 Accepted 143ms 2.223 MiB
#17 Accepted 129ms 3.598 MiB
#18 Accepted 158ms 5.125 MiB
#19 Accepted 289ms 8.191 MiB
#20 Accepted 27ms 1.836 MiB
#21 Accepted 136ms 3.562 MiB

Code

/*Rabbi Zidni Eilmaa*/

// We are open. We are looking for SHOTRUJ...
 
#include<bits/stdc++.h>
using namespace std;
 
typedef long long int ll;
typedef long double ld;
typedef string str;
typedef vector<ll> vll;
typedef vector<pair<ll, ll>> vpl;
typedef set<ll> sll;
typedef map<ll,ll> mll;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
double pi = acos(-1.0);
#define debug(x) cout<<#x<<" "<<x<<endl;
#define loop for(int i=1; i<=n; i++)
#define all(a) (a).begin(), (a).end()
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define min4(a,b,c,d) min(a,min(b,min(c,d)))
#define max4(a,b,c,d) max(a,max(b,max(c,d)))
#define forn(i, n) for(int i=1; i<=(int)n; i++)
#define ANS cout << ans << "\n"
#define PY cout << "YES\n"
#define PN cout << "NO\n" 

int mod = 1e9 + 7;

void init(){
    
}

ll BigMod(ll a, ll p, ll m){
    ll ans =1;
    while(p>0){
        if(p%2==1){
            ans=(ans*a)%m;
        }

        p/=2;
        a=(a*a)%m;
    }

    return (ans % mod);
}

vector<ll> facto(200005, -1);

ll fact(ll n){
    if(facto[n] != -1) return facto[n];
    if(n<2) return 1;
    return facto[n] = ((n * fact(n-1)) % mod);
}

ll nCr(ll n, ll r){
    ll ans = fact(n);
    ans = (ans * BigMod(fact(r), mod-2, mod)) % mod;
    ans = (ans * BigMod(fact(n-r), mod-2, mod)) % mod;
    return ans;
}

void solve()
{
    ll n, k;
    cin >> n >> k;
    ll x = 0;
    for(int i=1; i<=n; i++) {
        int a;
        cin >> a;
        x += a;
    }

    if(x < k) {
        cout << "0\n";
        return;
    }

    ll ans = BigMod(2, n-x, mod);
    ll p = 0;

    for(int i=k; i<=x; i++) {
        ll cur = nCr(x, i);
        // cout << i << ' ' << cur << endl;
        p = (p + cur) % mod;
    }

    ans = (ans * p) % mod;
    cout << ans - 1 << '\n';

    return;
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
 
    init();
    int t = 1;
    cin >> t;
    for(int i=1; i<=t; i++){
        // cout << "Case " << i << ": ";
        solve();
    }
 
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1094 Number of ways (Hard version)
Contest
Brain Booster #5
Language
C++20 (G++ 13.2.0)
Submit At
2024-09-05 16:43:52
Judged At
2024-11-11 02:59:39
Judged By
Score
100
Total Time
289ms
Peak Memory
8.191 MiB