結果

問題 No.2709 1975 Powers
ユーザー haihamabossu
提出日時 2024-03-31 14:03:52
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 165 ms / 2,000 ms
コード長 1,064 bytes
コンパイル時間 2,153 ms
コンパイル使用メモリ 200,128 KB
最終ジャッジ日時 2025-02-20 16:52:35
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

const ll MX = 2'000'010, X[4] = {10, 9, 7, 5};
ll n, p, q, pw[4][MX + 10];
void solve() {
  cin >> n >> p >> q;
  vector<ll> A(n);
  rep(i, n) cin >> A[i];
  sort(A.begin(), A.end());
  rep(i, 4) {
    ll x = X[i];
    pw[i][0] = 1;
    rep(j, MX) pw[i][j + 1] = (pw[i][j] * x) % p;
  }
  vector<ll> cnt(p, 0);
  for (ll di = 3; di < n; di++)
    cnt[pw[3][A[di]]]++;
  ll ans = 0;
  for (ll ci = 2; ci < n; ci++) {
    for (ll bi = ci - 1; bi >= 0; bi--) {
      for (ll ai = bi - 1; ai >= 0; ai--) {
        ll a = A[ai];
        ll b = A[bi];
        ll c = A[ci];
        ll now = q - (pw[0][a] + pw[1][b] + pw[2][c]) % p;
        if (now < 0)
          now += p;
        ans += cnt[now];
      }
    }
    if (ci < n - 1)
      cnt[pw[3][A[ci + 1]]]--;
  }
  cout << ans << '\n';
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  int T = 1;
  for (int t = 0; t < T; t++) {
    solve();
  }
  return 0;
}
0