結果

問題 No.2709 1975 Powers
ユーザー tobbie
提出日時 2024-04-27 17:35:09
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 531 ms / 2,000 ms
コード長 886 bytes
コンパイル時間 2,124 ms
コンパイル使用メモリ 176,208 KB
実行使用メモリ 112,768 KB
最終ジャッジ日時 2024-11-15 21:45:37
合計ジャッジ時間 12,076 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define rep(i, j, n) for (int i = (int)j; i < (int)(n); i++)
using ll = long long int;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;

int main() {
  int N, P, Q;
  cin >> N >> P >> Q;
  vi A(N);
  int amax = 0;
  rep(i, 0, N) {
    cin >> A[i];
    amax = max(A[i], amax);
  }
  sort(A.begin(), A.end());
  vi o = {10, 9, 7, 5};
  vvi a(amax+2, vi (4, 1));
  rep(i, 0, amax+1) {
    rep(k, 0, 4)
      a[i+1][k] = ((ll)a[i][k] * (ll)o[k]) % P;
  }
  auto dfs = [&](auto dfs, int x, int n, int depth) {
    x = (x + a[A[n]][depth]) % P;
    if (depth == 3) {
      if (x % P == Q)
	return 1;
      else
	return 0;
    }
    int ans = 0;
    rep(i, n+1, N)
      ans += dfs(dfs, x, i, depth+1);
    return ans;
  };
  int ans = 0;
  rep(i, 0, N)
    ans += dfs(dfs, 0, i, 0);
  cout << ans << endl;
  return 0;
}
0