/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Time Exceeded ≥1098ms ≥788.0 KiB
#2 Time Exceeded ≥1100ms ≥532.0 KiB

Code

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long int
#define endl '\n'
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key
#define all(v) v.begin(), v.end()
#define pb push_back //
#define mp make_pair
#define fi first                         //
#define se second                        //
#define yes cout << "YES" << endl        //
#define no cout << "NO" << endl          //
#define M 1000000007                     // 1e9+7
#define gcd(a, b) __gcd(a, b)            //
#define lcm(a, b) a *b / gcd(a, b)       //
#define memz(a) memset(a, 0, sizeof(a))  //
#define memn(a) memset(a, -1, sizeof(a)) //
ll fact[5001];
ll binary(ll a,ll b)
{
    ll ans=1;
    while(b)
    {
        if(b%2)ans=(ans*a)%M;
        a=(a*a)%M;
        b/=2;
    }
    return ans;
}
ll ncr(ll n,ll r)
{
    return (fact[n]*binary((fact[r]*fact[n-r])%M,M-2))%M;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    fact[0]=1;
    for(int i=1;i<=5000;i++)
    {
        fact[i]=(fact[i-1]*i)%M;
    }
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    ll tst;
    cin>>tst;
    for(ll test=1;test<=tst;test++)
    {
        //cout<<"Case "<<test<<": ";
        ll n,k;
        cin>>n>>k;
        ll ans=0;
        ll sum=0;
        for(int i=0;i<n;i++)
        {
            ll t;
            cin>>t;
            sum+=t;
        }
        ll z=(n-sum);
        z=(z*(z+1))/2;
        z++;
        for(int i=k;i<=sum;i++)
        {
            ans=(ans+(ncr(sum,i)*z)%M)%M;
        }
        if(ans>0)ans--;
        cout<<ans<<endl;
    }
}

Information

Submit By
Type
Submission
Problem
P1093 Number of Ways (Easy version)
Language
C++17 (G++ 13.2.0)
Submit At
2024-10-12 10:29:51
Judged At
2024-10-12 10:29:51
Judged By
Score
0
Total Time
≥1100ms
Peak Memory
≥788.0 KiB