QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#397994 | #3751. 组合数 | Graphcity | AC ✓ | 66ms | 199024kb | C++20 | 1.2kb | 2024-04-24 21:04:22 | 2024-04-24 21:04:23 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define i128 __int128
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rof(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
const int Maxn=5e3,inf=1e18;
int n,m,C[Maxn+5][Maxn+5];
inline void Solve()
{
m=min(m,n-m);
if(m==0) {cout<<1<<endl; return;}
if(m==1) {cout<<n<<endl; return;}
if(m==2) {cout<<n*(n-1)/2<<endl; return;}
if(n>=2000000) {cout<<inf<<endl; return;}
if(m==3) {cout<<min(inf,n*(n-1)*(n-2)/6)<<endl; return;}
if(n>=100000) {cout<<inf<<endl; return;}
if(m==4)
{
i128 res=(i128)n*(n-1)*(n-2)*(n-3)/24;
res=min(res,(i128)inf); cout<<(int)res<<endl; return;
}
if(n>=20000) {cout<<inf<<endl; return;}
if(m==5)
{
i128 res=(i128)n*(n-1)*(n-2)*(n-3)*(n-4)/120;
res=min(res,(i128)inf); cout<<(int)res<<endl; return;
}
if(n>=5000) {cout<<inf<<endl; return;}
cout<<C[n][m]<<endl;
}
signed main()
{
// freopen("1.in","r",stdin);
C[0][0]=1;
For(i,1,Maxn)
{
C[i][0]=1;
For(j,1,i) C[i][j]=min(inf,C[i-1][j]+C[i-1][j-1]);
}
while(cin>>n>>m) Solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 66ms
memory: 199024kb
input:
1 0 1 1 2 0 2 1 2 2 3 0 3 1 3 2 3 3 4 0 4 1 4 2 4 3 4 4 5 0 5 1 5 2 5 3 5 4 5 5 6 0 6 1 6 2 6 3 6 4 6 5 6 6 7 0 7 1 7 2 7 3 7 4 7 5 7 6 7 7 8 0 8 1 8 2 8 3 8 4 8 5 8 6 8 7 8 8 9 0 9 1 9 2 9 3 9 4 9 5 9 6 9 7 9 8 9 9 10 0 10 1 10 2 10 3 10 4 10 5 10 6 10 7 10 8 10 9 10 10 11 0 11 1 11 2 11 3 11 4 11 ...
output:
1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 1 6 15 20 15 6 1 1 7 21 35 35 21 7 1 1 8 28 56 70 56 28 8 1 1 9 36 84 126 126 84 36 9 1 1 10 45 120 210 252 210 120 45 10 1 1 11 55 165 330 462 462 330 165 55 11 1 1 12 66 220 495 792 924 792 495 220 66 12 1 1 13 78 286 715 1287 1716 1716 1287 715 286 78 13 ...
result:
ok 100000 tokens