比赛 寒假集训5 评测结果 AAATTWWTTT
题目名称 на меня 最终得分 30
用户昵称 LikableP 运行时间 6.898 s
代码语言 C++ 内存使用 3.43 MiB
提交时间 2026-03-01 10:13:59
显示代码纯文本
#include <cstdio>
typedef long long ll;

const int MAXN = 2e5 + 10;

ll n, p;
ll a[MAXN], b[MAXN];
ll fac[10010], inv[10010];

ll C(ll x, ll y) {
  if (x < 0 || y < 0 || x < y) return 0;
  return fac[x] * inv[y] % p * inv[x - y] % p;
}

ll kasumi(ll x, ll y) {
  ll res = 1;
  while (y) {
    if (y & 1) res = res * x % p;
    y >>= 1;
    x = x * x % p;
  }
  return res;
}

int main() {
  #ifdef LOCAL
    freopen("!input.in", "r", stdin);
    freopen("!output.out", "w", stdout);
  #else
    freopen("BBQ.in", "r", stdin);
    freopen("BBQ.out", "w", stdout);
  #endif

  scanf("%lld %lld", &n, &p);
  for (int i = 1; i <= n; ++i) {
    scanf("%lld %lld", &a[i], &b[i]);
  }

  if (p == 2) {
    printf("%lld\n", 1);
  } else if (p == 3) {
    printf("%lld\n", 1);
  } else {
    fac[0] = inv[0] = 1;
    for (ll i = 1; i <= 10000; ++i) {
      fac[i] = fac[i - 1] * i % p;
      inv[i] = kasumi(fac[i], p - 2);
    }

    ll ans = 0;
    for (ll i = 1; i <= n; ++i) {
      for (ll j = i + 1; j <= n; ++j) {
        ans = (ans + C(a[i] + a[j] + b[i] + b[j], a[i] + a[j])) % p;
      }
    }

    printf("%lld\n", ans);
  }
  return 0;
}