Submission #28870025
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#include "debug.h"
#endif
#define fast { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define pb push_back
#define eb emplace_back
#define ll long long
#define ld long double
#define vll vector<ll>
#define infl LONG_LONG_MAX
#define infd LDBL_MAX
#define F first
#define S second
#define pll pair<ll,ll>
#define G(a,b) get<a>(b)
#define ALL(v) v.begin(),v.end()
#define MP make_pair
#define MT make_tuple
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fi(i,a,b) for(ll i=(b-1);i>=a;i--)
#define nl cout<<"\n";
#define sz(x) (ll)x.size()
#define rem_dup(v) v.resize(unique(v.begin(), v.end()) - v.begin())
template<class T>
using min_heap = priority_queue<T,vector<T>,greater<T> >;
clock_t startTime;
double getCurrentTime() {
return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}
const ll N=1e5+5,p=998244353;
ll pow_mod_p(ll a,ll b)
{
a=a%p;
ll res=1;
while(b>0)
{
if(b&1) res=(res*a)%p;
b=b>>1;
a=(a*a)%p;
}
return res;
}
inline ll mod_inv(ll x)
{
return pow_mod_p(x,p-2);
}
ll n,k,a[N],fac[N],faci[N];
ll nCr(ll x,ll y){
if(x<y) return 0;
else if(x==y) return 1;
ll den1=y,den2=x-y;
if(den1<den2) swap(den1,den2);
ll ans=1;
f(i,den1+1,x+1){
ans=(ans*i)%p;
}
ans=(ans*faci[den2])%p;
return ans;
}
void func()
{
cin>>n>>k;
f(i,1,n+1) cin>>a[i];
fac[0]=1;
f(i,1,k+1) fac[i]=(fac[i-1]*i)%p;
faci[k]=mod_inv(fac[k]);
fi(i,0,k) faci[i]=(faci[i+1]*(i+1))%p;
ll s=0;
f(i,2,n+1){
s+=a[i];
}
if(a[1]<s+k){
cout<<"0\n";
return;
}
ll rem=a[1]-s-k,ans=nCr(k+rem-1,rem);
f(i,2,n+1) ans=(ans*nCr(k+a[i]-1,a[i]))%p;
cout<<ans<<"\n";
}
int main()
{
startTime = clock();
fast
//#ifndef ONLINE_JUDGE
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
//#endif // ONLINE_JUDGE
cout<<fixed<<setprecision(10);
int ntc=1;
// cin>>ntc;
f(i,1,ntc+1)
{
// cout<<"Case #"<<i<<": ";
func();
// clr();
}
// cout<<getCurrentTime()<<"\n";
return 0;
}
Submission Info
| Submission Time |
|
| Task |
C - The Majority |
| User |
shinigami11 |
| Language |
C++ (GCC 9.2.1) |
| Score |
500 |
| Code Size |
2202 Byte |
| Status |
AC |
| Exec Time |
16 ms |
| Memory |
4444 KiB |
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
500 / 500 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
sample_01.txt, sample_02.txt, sample_03.txt |
| All |
random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, sample_01.txt, sample_02.txt, sample_03.txt |
| Case Name |
Status |
Exec Time |
Memory |
| random_01.txt |
AC |
7 ms |
3480 KiB |
| random_02.txt |
AC |
13 ms |
4444 KiB |
| random_03.txt |
AC |
2 ms |
3620 KiB |
| random_04.txt |
AC |
15 ms |
4312 KiB |
| random_05.txt |
AC |
2 ms |
3500 KiB |
| random_06.txt |
AC |
11 ms |
4364 KiB |
| random_07.txt |
AC |
3 ms |
3576 KiB |
| random_08.txt |
AC |
13 ms |
4312 KiB |
| random_09.txt |
AC |
2 ms |
3552 KiB |
| random_10.txt |
AC |
15 ms |
4408 KiB |
| random_11.txt |
AC |
2 ms |
3548 KiB |
| random_12.txt |
AC |
15 ms |
4384 KiB |
| random_13.txt |
AC |
16 ms |
4384 KiB |
| random_14.txt |
AC |
11 ms |
4184 KiB |
| random_15.txt |
AC |
9 ms |
4076 KiB |
| random_16.txt |
AC |
12 ms |
4120 KiB |
| random_17.txt |
AC |
10 ms |
4200 KiB |
| random_18.txt |
AC |
10 ms |
3908 KiB |
| random_19.txt |
AC |
12 ms |
4240 KiB |
| random_20.txt |
AC |
3 ms |
3600 KiB |
| random_21.txt |
AC |
5 ms |
3728 KiB |
| random_22.txt |
AC |
4 ms |
3644 KiB |
| random_23.txt |
AC |
5 ms |
3780 KiB |
| random_24.txt |
AC |
3 ms |
3920 KiB |
| random_25.txt |
AC |
4 ms |
3768 KiB |
| random_26.txt |
AC |
10 ms |
3892 KiB |
| random_27.txt |
AC |
14 ms |
3688 KiB |
| random_28.txt |
AC |
14 ms |
4120 KiB |
| random_29.txt |
AC |
16 ms |
4236 KiB |
| random_30.txt |
AC |
13 ms |
4060 KiB |
| sample_01.txt |
AC |
2 ms |
3664 KiB |
| sample_02.txt |
AC |
2 ms |
3528 KiB |
| sample_03.txt |
AC |
2 ms |
3544 KiB |