| 比赛 |
寒假集训5 |
评测结果 |
AAAWWAWWWW |
| 题目名称 |
на меня |
最终得分 |
40 |
| 用户昵称 |
ChenBp |
运行时间 |
1.652 s |
| 代码语言 |
C++ |
内存使用 |
3.93 MiB |
| 提交时间 |
2026-03-01 10:32:28 |
显示代码纯文本
#include <iostream>
#include <cstdio>
using namespace std;
const int N=1e4+4;
typedef long long ll;
ll jc[N],inv[N];
ll n,p;
ll ksm(ll x,ll y){
ll res=1;
while(y){
if(y&1){
res=(res*x)%p;
}
x=(x*x)%p;
y>>=1;
}
return res;
}
ll a[N],b[N];
ll C(ll x,ll y){
if(y>x) return 0;
return jc[x]*inv[y]%p*inv[x-y]%p;
}
int main(){
freopen("BBQ.in","r",stdin);
freopen("BBQ.out","w",stdout);
cin>>n>>p;
jc[0]=1;
for(int i=1;i<=N-4;i++){
jc[i]=(jc[i-1]*i)%p;
inv[i]=ksm(jc[i],p-2);
}
for(int i=1;i<=n;i++){
cin>>a[i]>>b[i];
}
ll ans=0;
for(int i=1;i<=n;i++){
for(int j=i+1;j<=n;j++){
ans+=C(a[i]+a[j]+b[i]+b[j],a[i]+a[j]);
ans%=p;
}
}
cout<<ans;
return 0;
}