/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Time Exceeded ≥1082ms ≥572.0 KiB
#2 Time Exceeded ≥1086ms ≥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++;
        if(sum>k)
        {
            ans=fact[sum]*binary(fact[k-1],M-2);
        }
        ans=(ans*z)%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:33:26
Judged At
2024-11-11 02:37:39
Judged By
Score
0
Total Time
≥1086ms
Peak Memory
≥572.0 KiB