結果

問題 No.2709 1975 Powers
ユーザー tobbietobbie
提出日時 2024-04-27 16:01:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,015 bytes
コンパイル時間 1,688 ms
コンパイル使用メモリ 179,892 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-04-27 16:01:30
合計ジャッジ時間 5,145 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,624 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます

ソースコード

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);
  rep(i, 0, N)
    cin >> A[i];
  sort(A.begin(), A.end());
  vi o = {10, 9, 7, 5};
  vvi a(N, vector<int> (4));
  rep(i, 0, N) {
    rep(j, 0, i+1) {
      int p = 1;
      rep(k, 0, A[i])
	p = ((ll)p * (ll)o[j]) % P;
      a[i][j] = p;
    }
  }
  vvvi y(P, vvi (N, vi (4, -1)));
  auto dfs = [&](auto dfs, int x, int n, int depth, int ans) {
    x = (x + a[n][depth]) % P;
    y[x][n][depth] = x;
    if (depth == 3) {
      if (x % P == Q)
	return ans + 1;
      else
	return ans;
    }
    rep(i, n+1, N) {
      if (y[x][i][depth+1] >= 0)
	ans = y[x][i][depth+1];
      else
	ans = dfs(dfs, x, i, depth+1, ans);
    }
    return ans;
  };
  int ans = 0;
  rep(i, 0, N)
    ans += dfs(dfs, 0, i, 0, 0);
  cout << ans << endl;
  return 0;
}
0