結果

問題 No.2709 1975 Powers
ユーザー ripityripity
提出日時 2024-03-31 13:53:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,008 bytes
コンパイル時間 2,396 ms
コンパイル使用メモリ 219,724 KB
実行使用メモリ 80,384 KB
最終ジャッジ日時 2024-03-31 13:53:44
合計ジャッジ時間 28,447 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 41 ms
6,676 KB
testcase_03 AC 1,067 ms
8,704 KB
testcase_04 TLE -
testcase_05 AC 1,342 ms
29,056 KB
testcase_06 AC 591 ms
24,064 KB
testcase_07 AC 3 ms
6,676 KB
testcase_08 AC 563 ms
23,552 KB
testcase_09 AC 1,482 ms
47,360 KB
testcase_10 AC 4 ms
6,676 KB
testcase_11 AC 78 ms
6,676 KB
testcase_12 AC 174 ms
8,832 KB
testcase_13 AC 1,563 ms
57,728 KB
testcase_14 AC 295 ms
12,416 KB
testcase_15 AC 345 ms
11,904 KB
testcase_16 AC 1,305 ms
42,112 KB
testcase_17 AC 12 ms
6,676 KB
testcase_18 AC 231 ms
12,928 KB
testcase_19 TLE -
testcase_20 AC 32 ms
6,676 KB
testcase_21 AC 514 ms
22,016 KB
testcase_22 AC 1,838 ms
7,296 KB
testcase_23 TLE -
testcase_24 TLE -
testcase_25 TLE -
testcase_26 TLE -
権限があれば一括ダウンロードができます

ソースコード

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, 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)]++;
  }
  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 = f(10, A[i], P)+f(9, A[j], P)+f(7, A[k], P);
        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