結果

問題 No.2709 1975 Powers
ユーザー ripityripity
提出日時 2024-03-31 13:56:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 757 ms / 2,000 ms
コード長 1,149 bytes
コンパイル時間 2,656 ms
コンパイル使用メモリ 221,464 KB
実行使用メモリ 55,808 KB
最終ジャッジ日時 2024-03-31 13:57:10
合計ジャッジ時間 8,938 ms
ジャッジサーバーID
(参考情報)
judge10 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 4 ms
6,676 KB
testcase_03 AC 55 ms
7,168 KB
testcase_04 AC 551 ms
40,448 KB
testcase_05 AC 204 ms
20,608 KB
testcase_06 AC 148 ms
17,792 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 138 ms
17,408 KB
testcase_09 AC 409 ms
32,896 KB
testcase_10 AC 3 ms
6,676 KB
testcase_11 AC 12 ms
6,676 KB
testcase_12 AC 23 ms
7,040 KB
testcase_13 AC 481 ms
40,704 KB
testcase_14 AC 43 ms
9,728 KB
testcase_15 AC 44 ms
9,216 KB
testcase_16 AC 322 ms
29,568 KB
testcase_17 AC 3 ms
6,676 KB
testcase_18 AC 50 ms
9,984 KB
testcase_19 AC 612 ms
45,056 KB
testcase_20 AC 7 ms
6,676 KB
testcase_21 AC 121 ms
16,128 KB
testcase_22 AC 88 ms
6,676 KB
testcase_23 AC 757 ms
55,808 KB
testcase_24 AC 704 ms
53,504 KB
testcase_25 AC 519 ms
36,224 KB
testcase_26 AC 240 ms
15,872 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

long long f(long long x, long long n, long long MOD) {
  long long ret = 1;
  while(n) {
    if(n&1) {
      ret *= x;
      ret %= MOD;
    }
    x *= x;
    x %= MOD;
    n >>= 1;
  }
  return ret;
}

int main() {
  long long N, P, Q;
  cin >> N >> P >> Q;
  vector<long long> A(N);
  for(int i = 0; i < N; i++) {
    cin >> A[i];
  }
  sort(A.begin(), A.end());
  vector cnt(N+1, unordered_map<long long, long long>());
  for(int i = N-1; i >= 0; i--) {
    cnt[i] = cnt[i+1];
    cnt[i][f(5, A[i], P)]++;
  }
  vector po(N, vector<long long>(15));
  for(int i = 0; i < N; i++) {
    for(int j = 0; j < 15; j++) {
      po[i][j] = f(j, A[i], P);
    }
  }
  long long ans = 0;
  for(int i = 0; i < N; ++i) {
    for(int j = i+1; j < N; ++j) {
      for(int k = j+1; k < N; ++k) {
        long long s = po[i][10]+po[j][9]+po[k][7];
        s %= P;
        long long t = (P+Q-s)%P;
        // cout << A[i] << " " << A[j] << " " << A[k] << ": " << f(10, A[i], P) << " " << f(9, A[j], P) << " " << f(7, A[k], P) << " " << t << endl;
        ans += cnt[k+1][t];
      }
    }
  }
  cout << ans << endl;
}
0