/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 1ms 324.0 KiB
#3 Accepted 2ms 564.0 KiB
#4 Accepted 2ms 536.0 KiB
#5 Accepted 2ms 568.0 KiB
#6 Accepted 2ms 320.0 KiB
#7 Accepted 2ms 320.0 KiB
#8 Accepted 3ms 532.0 KiB
#9 Accepted 2ms 544.0 KiB
#10 Accepted 2ms 532.0 KiB
#11 Accepted 2ms 324.0 KiB
#12 Accepted 2ms 532.0 KiB
#13 Accepted 3ms 324.0 KiB
#14 Accepted 2ms 536.0 KiB
#15 Accepted 2ms 484.0 KiB
#16 Accepted 16ms 532.0 KiB
#17 Accepted 24ms 556.0 KiB
#18 Accepted 14ms 536.0 KiB
#19 Accepted 12ms 324.0 KiB
#20 Accepted 14ms 536.0 KiB
#21 Accepted 22ms 320.0 KiB

Code

#include <bits/stdc++.h>
using namespace std;
#define SC               scanf
#define PF               printf
#define ull              unsigned long long
#define ld               long double
#define F                first
#define S                second
#define pb               push_back
#define sort_a(a)        sort(a.begin(),a.end());
#define sort_d(a)        sort(a.rbegin(),a.rend());
#define READ(f)          freopen(f, "r", stdin)
#define WRITE(f)         freopen(f, "w", stdout)
#define rev(s)           reverse(s.begin(),s.end())
#define P(ok)            cout << (ok ? "YES\n": "NO\n")
#define __Heart__              ios_base :: sync_with_stdio(false); cin.tie(NULL);
#define ll long long
typedef pair< ll , ll>                   PII;
const int M = 1e9 + 7 ;
ll BigMod(ll n,ll p)
{
    if(p == 0) return 1;
    if( p % 2 == 0)
    {
        ll ret = BigMod(n, p/2);
        return ((ret % M ) *(ret % M))% M;
    }
    else return ((n % M)*(BigMod(n, p-1 ) % M))% M;

}


ll nCrMod(ll n, ll r) {
    if (r > n) return 0;
    if (r == 0 || r == n) return 1;

    ll Res = 1;
    for (ll i = 0; i < r; ++i) {
        Res *= (n - i);
        Res %= M;
        Res *= BigMod(i + 1, M - 2);
        Res %= M;
    }
    return Res;
}

ll sumNcRtoN(ll n, ll r) {
    ll totSum = BigMod(2, n);
    ll subtractSum = 0;
    ll currentCr = 1;
    for (ll i = 0; i < r; ++i) {
        subtractSum = (subtractSum + currentCr) % M;
        currentCr = (currentCr * (n - i)) % M;
        currentCr = (currentCr * BigMod(i + 1, M - 2)) % M;
    }

    return (totSum - subtractSum + M) % M;
}

void solve()
{
   ll n , k , sum = 0 , a; cin >> n >> k ;
   for(int i = 0 ; i < n ; i++) cin >> a , sum += a ;
   if(sum < k){
    cout << 0 << "\n" ;
   }
   else {
    ll Ans = (BigMod(2 , n - sum) % M * (sumNcRtoN(sum , k) % M)) % M ;
    Ans-- ;
    cout << Ans << "\n" ;
   }
}
int main()
{
     __Heart__
       int t ; cin >> t ; while(t--) solve() ;
}

Information

Submit By
Type
Submission
Problem
P1094 Number of ways (Hard version)
Language
C++20 (G++ 13.2.0)
Submit At
2024-08-21 17:56:55
Judged At
2024-11-11 03:06:34
Judged By
Score
100
Total Time
24ms
Peak Memory
568.0 KiB