| 比赛 |
寒假集训5 |
评测结果 |
AAAEEEEEEE |
| 题目名称 |
на меня |
最终得分 |
30 |
| 用户昵称 |
ychyyx |
运行时间 |
2.236 s |
| 代码语言 |
C++ |
内存使用 |
4.71 MiB |
| 提交时间 |
2026-03-01 11:22:25 |
显示代码纯文本
#include<iostream>
#include<cstdio>
#define ll long long
using namespace std;
ll a[100005],b[100005];
ll n,p;
ll ans;
ll s[8005],ins[8005];
ll qpow(ll a,ll k){
ll res=1;
while(k){
if(k&1)
res=res*a%p;
k>>=1;
a=a*a%p;
}
return res;
}
ll c(ll n,ll m){
if(n<m) return 0;
return s[n]*ins[m]%p*ins[n-m]%p;
}
int main(){
freopen("BBQ.in","r",stdin);
freopen("BBQ.out","w",stdout);
scanf("%lld%lld",&n,&p);
s[0]=ins[0]=1;
for(ll i=1;i<=8000;i++){
s[i]=(s[i-1]*i)%p;
ins[i]=ins[i-1]*qpow(i,p-2)%p;
}
for(int i=1;i<=n;i++)
scanf("%lld%lld",&a[i],&b[i]);
for(int i=1;i<=n;i++){
for(int j=i+1;j<=n;j++){
ans=(ans+c(a[i]+a[j]+b[i]+b[j],a[i]+a[j]))%p;
}
}
printf("%lld",ans);
return 0;
}