/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 7ms 3.555 MiB
#2 Accepted 6ms 3.52 MiB
#3 Wrong Answer 6ms 3.52 MiB
#4 Wrong Answer 6ms 3.52 MiB
#5 Wrong Answer 6ms 3.566 MiB
#6 Wrong Answer 9ms 3.449 MiB
#7 Wrong Answer 12ms 3.5 MiB
#8 Wrong Answer 18ms 3.551 MiB
#9 Wrong Answer 12ms 3.523 MiB
#10 Wrong Answer 12ms 3.547 MiB
#11 Accepted 7ms 3.523 MiB
#12 Wrong Answer 6ms 3.52 MiB
#13 Wrong Answer 6ms 3.562 MiB
#14 Wrong Answer 6ms 3.551 MiB
#15 Wrong Answer 6ms 3.566 MiB

Code

/*
 *   Copyright (c) 2024 Emon Thakur
 *   All rights reserved.
 */
#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;
using minheap = priority_queue<long long, vector<long long>, greater<long long>>;
typedef tree<int, null_type, greater_equal<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key

#define ll long long
#define ld long double
#define MOD 1000000007
#define pie 2*(acos(0.0))
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define pb push_back
#define endl '\n'
#define lcm(a,b) (a*b)/(__gcd<ll>(a,b))
#define print(v) for(auto e:v) cout<<e<<" "; cout<<endl;
#define printp(v) for(auto e:v) cout<<e.first<<" "<<e.second<<endl;
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(v.rbegin(),v.rend())
#define life_is_a_race ios::sync_with_stdio(false); cin.tie(nullptr);

// Modulo nCr
const int Max = 2e5 + 5, mod = 998244353;
ll fact[Max], factInv[Max];

template<class T> T Pow(T a, ll b) {
    T ans = 1;
    while (b)
    {
        if (b & 1) ans = (ans * a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return ans;
}

void build_fact() {
    fact[0] = 1;
    for(int i = 1; i < Max; i++)
    {
        fact[i] = 1LL * fact[i - 1] * i % mod;
    }
    factInv[Max - 1] = Pow(fact[Max - 1], mod - 2);
    for(int i = Max - 2; i >= 0; i--)
    {
        factInv[i] = 1LL * factInv[i + 1] * (i + 1) % mod;
    }
    return;
}

ll nCr_mod(int n, int r) {
    if(n < r or n < 0 or r < 0) return 0;
    return 1LL * fact[n] * factInv[r] % mod * factInv[n - r] % mod;
}

int nPr_mod(int n, int r) { // nPr = nCr * r! 
    if(n < r or n < 0 or r < 0) return 0;
    return (1LL * nCr_mod(n, r) * fact[r]) % mod;
}

void solve(int tc)
{
    //cout<<"Case "<<tc<<": ";
    ll n,k; cin >> n >> k;
    ll a[n],sum=0;
    for(int i=0;i<n;i++) cin >> a[i], sum+=a[i];
    if(sum<k)
    {
        cout<<0<<endl;
        return;
    }
    ll ans = 0, one;
    ll z = Pow(2,n-sum);
    ans = z-1;
    for(ll i=sum-1;i>=k;i--)
    {
        one = sum-i;
        ans += ((nCr_mod(sum,one) * z) % mod);
        ans = ans%mod;
    }
    cout << ans % mod << endl;
}
int main()
{
    life_is_a_race
    build_fact();
    int t=1; 
    cin>>t;
    for(int i=1;i<=t;i++) solve(i);
}

Information

Submit By
Type
Submission
Problem
P1093 Number of Ways (Easy version)
Language
C++20 (G++ 13.2.0)
Submit At
2024-09-04 20:44:15
Judged At
2024-09-04 20:44:15
Judged By
Score
13
Total Time
18ms
Peak Memory
3.566 MiB