Submission #65673700
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
const int MOD=998244353;
vector<long long> nfact, nfactInv;
long long modpow(long long x, long long n, long long m) {
if (n == 0) return 1%m;
long long u = modpow(x,n/2,m);
u = (u*u)%m;
if (n%2 == 1) u = (u*x)%m;
return u;
}
long long ncr(long long n, long long r,int N=4000000){
if(!nfact.size()){
nfact.resize(N+1);
nfact[0]=1;
for(int i=1; i<=N; i++){
nfact[i]=nfact[i-1]*i;
nfact[i]%=MOD;
}
nfactInv.resize(N+1);
nfactInv[N]=modpow(nfact[N],MOD-2,MOD);
for(int i=N-1; i>=0; i--){
nfactInv[i]=nfactInv[i+1]*(i+1);
nfactInv[i]%=MOD;
}
}
if(r>n || r<0) return 0;
long long d1=nfactInv[r];
long long d2=nfactInv[n-r];
long long mult=(d1*d2)%MOD;
return (nfact[n]*mult)%MOD;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int A,O,B,G;
cin>>A>>O>>B>>G;
int tot=A+O+B+G;
long long ans=0;
for(int i=A;i<=A+O;i++){
long long val=ncr(i-1,A-1)*ncr(tot-i,G+O-i+A);
val%=MOD;
ans+=val;
ans%=MOD;
}
cout<<ans;
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | E - Fruit Lineup |
| User | usernameson |
| Language | C++ 20 (gcc 12.2) |
| Score | 475 |
| Code Size | 1183 Byte |
| Status | AC |
| Exec Time | 69 ms |
| Memory | 65752 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 475 / 475 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt |
| All | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 02_max_00.txt, 02_max_01.txt, 02_max_02.txt, 02_max_03.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00_sample_00.txt | AC | 59 ms | 65604 KiB |
| 00_sample_01.txt | AC | 60 ms | 65616 KiB |
| 00_sample_02.txt | AC | 59 ms | 65584 KiB |
| 01_random_00.txt | AC | 63 ms | 65512 KiB |
| 01_random_01.txt | AC | 68 ms | 65512 KiB |
| 01_random_02.txt | AC | 65 ms | 65600 KiB |
| 01_random_03.txt | AC | 62 ms | 65660 KiB |
| 01_random_04.txt | AC | 60 ms | 65516 KiB |
| 01_random_05.txt | AC | 68 ms | 65752 KiB |
| 01_random_06.txt | AC | 69 ms | 65548 KiB |
| 01_random_07.txt | AC | 65 ms | 65660 KiB |
| 01_random_08.txt | AC | 67 ms | 65652 KiB |
| 01_random_09.txt | AC | 60 ms | 65600 KiB |
| 02_max_00.txt | AC | 69 ms | 65508 KiB |
| 02_max_01.txt | AC | 69 ms | 65560 KiB |
| 02_max_02.txt | AC | 69 ms | 65604 KiB |
| 02_max_03.txt | AC | 69 ms | 65556 KiB |