結果

問題 No.2709 1975 Powers
ユーザー rurunrurun
提出日時 2024-03-31 13:59:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,958 ms / 2,000 ms
コード長 1,116 bytes
コンパイル時間 2,410 ms
コンパイル使用メモリ 211,700 KB
実行使用メモリ 287,152 KB
最終ジャッジ日時 2024-04-01 12:34:30
合計ジャッジ時間 25,609 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 112 ms
86,644 KB
testcase_03 AC 1,072 ms
142,948 KB
testcase_04 AC 1,679 ms
242,360 KB
testcase_05 AC 1,236 ms
193,324 KB
testcase_06 AC 500 ms
62,964 KB
testcase_07 AC 26 ms
28,356 KB
testcase_08 AC 577 ms
181,448 KB
testcase_09 AC 1,284 ms
213,236 KB
testcase_10 AC 27 ms
30,152 KB
testcase_11 AC 105 ms
42,992 KB
testcase_12 AC 272 ms
145,832 KB
testcase_13 AC 1,345 ms
260,516 KB
testcase_14 AC 313 ms
80,936 KB
testcase_15 AC 431 ms
173,384 KB
testcase_16 AC 1,016 ms
111,284 KB
testcase_17 AC 39 ms
33,472 KB
testcase_18 AC 315 ms
151,992 KB
testcase_19 AC 1,639 ms
216,140 KB
testcase_20 AC 96 ms
80,280 KB
testcase_21 AC 564 ms
179,984 KB
testcase_22 AC 1,958 ms
287,152 KB
testcase_23 AC 1,923 ms
228,476 KB
testcase_24 AC 1,825 ms
134,484 KB
testcase_25 AC 1,908 ms
220,360 KB
testcase_26 AC 1,930 ms
247,084 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

template<typename T>
T modpow(T a, T b, T mod=998244353) {
  T res = 1;
  while (b > 0) {
    if (b&1) (res *= a) %= mod;
    (a *= a) %= mod;
    b >>= 1;
  }
  return res;
}

int main() {
  lint n, p, q;
  cin >> n >> p >> q;
  vector<lint> vec(n);
  for (int i = 0; i < n; i++) cin >> vec[i];
  sort(vec.begin(), vec.end());
  vector<vector<lint>> cnt(n+1, vector<lint>(p));  // iより後ろでjあまるものの数
  vector rui = cnt;


  for (int i = 0; i < n; i++) {
    cnt[i][modpow(5LL, vec[i], p)]++;
  }
  for (int i = n-1; i >= 0; i--) {
    for (int j = 0; j < p; j++) {
      rui[i][j] = rui[i+1][j]+cnt[i+1][j];
    }
  }
  lint 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++) {
        lint now = modpow(10LL, vec[i], p)+modpow(9LL, vec[j], p)+ modpow(7LL, vec[k], p);
        now %= p;
        ans += rui[k][(q+p-now)%p];
      }
    }
  }
  cout << ans << endl;
  return 0;
  for (auto x : rui) {
    for (auto y : x) cout << y << " ";
    cout << endl;
  }
}
0