結果

問題 No.2709 1975 Powers
ユーザー 👑 emthrmemthrm
提出日時 2024-03-31 14:19:20
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 105 ms / 2,000 ms
コード長 1,529 bytes
コンパイル時間 3,350 ms
コンパイル使用メモリ 260,484 KB
実行使用メモリ 74,752 KB
最終ジャッジ日時 2024-03-31 14:19:29
合計ジャッジ時間 5,197 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 25 ms
24,192 KB
testcase_03 AC 61 ms
38,656 KB
testcase_04 AC 91 ms
63,488 KB
testcase_05 AC 74 ms
50,816 KB
testcase_06 AC 30 ms
18,304 KB
testcase_07 AC 8 ms
9,600 KB
testcase_08 AC 58 ms
47,744 KB
testcase_09 AC 80 ms
55,680 KB
testcase_10 AC 9 ms
9,984 KB
testcase_11 AC 17 ms
13,312 KB
testcase_12 AC 45 ms
38,912 KB
testcase_13 AC 91 ms
67,712 KB
testcase_14 AC 33 ms
22,784 KB
testcase_15 AC 53 ms
45,824 KB
testcase_16 AC 53 ms
30,336 KB
testcase_17 AC 10 ms
10,880 KB
testcase_18 AC 46 ms
40,448 KB
testcase_19 AC 87 ms
56,960 KB
testcase_20 AC 24 ms
22,528 KB
testcase_21 AC 58 ms
47,488 KB
testcase_22 AC 105 ms
74,752 KB
testcase_23 AC 93 ms
60,288 KB
testcase_24 AC 71 ms
36,352 KB
testcase_25 AC 90 ms
57,856 KB
testcase_26 AC 97 ms
64,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 998244353;
// constexpr int MOD = 1000000007;
constexpr int DY4[]{1, 0, -1, 0}, DX4[]{0, -1, 0, 1};
constexpr int DY8[]{1, 1, 0, -1, -1, -1, 0, 1};
constexpr int DX8[]{0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U>
inline bool chmax(T& a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U>
inline bool chmin(T& a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << fixed << setprecision(20);
  }
} iosetup;

long long mod_pow(long long x, long long n, const int m) {
  if ((x %= m) < 0) x += m;
  long long res = 1;
  for (; n > 0; n >>= 1) {
    if (n & 1) res = (res * x) % m;
    x = (x * x) % m;
  }
  return res;
}

int main() {
  int n, p, q; cin >> n >> p >> q;
  vector<int> A(n);
  for (int& A_i : A) cin >> A_i;
  ranges::sort(A);
  vector x(n, vector(p, 0));
  REP(a, n) FOR(b, a + 1, n) ++x[b][(mod_pow(10, A[a], p) + mod_pow(9, A[b], p)) % p];
  FOR(i, 1, n) REP(j, p) x[i][j] += x[i - 1][j];
  ll ans = 0;
  FOR(c, 2, n) FOR(d, c + 1, n) {
    const int r = (q - (mod_pow(7, A[c], p) + mod_pow(5, A[d], p)) % p + p) % p;
    ans += x[c - 1][r];
  }
  cout << ans << '\n';
  return 0;
}
0