結果

問題 No.2709 1975 Powers
ユーザー haihamabossuhaihamabossu
提出日時 2024-03-31 14:03:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 162 ms / 2,000 ms
コード長 1,064 bytes
コンパイル時間 2,126 ms
コンパイル使用メモリ 207,408 KB
実行使用メモリ 66,688 KB
最終ジャッジ日時 2024-03-31 14:04:00
合計ジャッジ時間 7,288 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 146 ms
66,040 KB
testcase_01 AC 146 ms
66,040 KB
testcase_02 AC 147 ms
66,560 KB
testcase_03 AC 156 ms
66,304 KB
testcase_04 AC 162 ms
66,432 KB
testcase_05 AC 157 ms
66,432 KB
testcase_06 AC 152 ms
66,176 KB
testcase_07 AC 146 ms
66,552 KB
testcase_08 AC 151 ms
66,560 KB
testcase_09 AC 159 ms
66,432 KB
testcase_10 AC 146 ms
66,552 KB
testcase_11 AC 147 ms
66,176 KB
testcase_12 AC 150 ms
66,688 KB
testcase_13 AC 159 ms
66,560 KB
testcase_14 AC 149 ms
66,176 KB
testcase_15 AC 151 ms
66,560 KB
testcase_16 AC 158 ms
66,176 KB
testcase_17 AC 147 ms
66,300 KB
testcase_18 AC 149 ms
66,560 KB
testcase_19 AC 161 ms
66,432 KB
testcase_20 AC 147 ms
66,560 KB
testcase_21 AC 151 ms
66,560 KB
testcase_22 AC 161 ms
66,560 KB
testcase_23 AC 162 ms
66,432 KB
testcase_24 AC 162 ms
66,176 KB
testcase_25 AC 162 ms
66,432 KB
testcase_26 AC 162 ms
66,432 KB
権限があれば一括ダウンロードができます

ソースコード

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