結果

問題 No.2709 1975 Powers
ユーザー takumi152takumi152
提出日時 2024-03-31 14:23:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 705 ms / 2,000 ms
コード長 1,218 bytes
コンパイル時間 1,070 ms
コンパイル使用メモリ 106,840 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-31 14:24:00
合計ジャッジ時間 8,932 ms
ジャッジサーバーID
(参考情報)
judge10 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 7 ms
6,676 KB
testcase_03 AC 346 ms
6,676 KB
testcase_04 AC 579 ms
6,676 KB
testcase_05 AC 386 ms
6,676 KB
testcase_06 AC 122 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 109 ms
6,676 KB
testcase_09 AC 389 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 12 ms
6,676 KB
testcase_12 AC 31 ms
6,676 KB
testcase_13 AC 405 ms
6,676 KB
testcase_14 AC 56 ms
6,676 KB
testcase_15 AC 65 ms
6,676 KB
testcase_16 AC 307 ms
6,676 KB
testcase_17 AC 3 ms
6,676 KB
testcase_18 AC 39 ms
6,676 KB
testcase_19 AC 588 ms
6,676 KB
testcase_20 AC 4 ms
6,676 KB
testcase_21 AC 107 ms
6,676 KB
testcase_22 AC 676 ms
6,676 KB
testcase_23 AC 705 ms
6,676 KB
testcase_24 AC 676 ms
6,676 KB
testcase_25 AC 683 ms
6,676 KB
testcase_26 AC 676 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <unordered_set>
#include <unordered_map>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;

const ll mod = 998244353;

ll modpow(ll a, ll b, ll m = mod) {
  ll r = 1;
  while (b > 0) {
    if (b & 1) r = (r * a) % m;
    a = (a * a) % m;
    b >>= 1;
  }
  return r;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll n, p, q;
  cin >> n >> p >> q;
  vector<ll> a(n);
  for (auto &x: a) cin >> x;

  sort(a.begin(), a.end());

  vector<ll> pow10mod(n), pow9mod(n), pow7mod(n), pow5mod(n);
  for (int i = 0; i < n; i++) {
    pow10mod[i] = modpow(10, a[i], p);
    pow9mod[i] = modpow(9, a[i], p);
    pow7mod[i] = modpow(7, a[i], p);
    pow5mod[i] = modpow(5, a[i], p);
  }

  ll 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++) {
        for (int l = k + 1; l < n; l++) {
          ll val = (pow10mod[i] + pow9mod[j] + pow7mod[k] + pow5mod[l]) % p;
          if (val == q) ans++;
        }
      }
    }
  }

  cout << ans << endl;

  return 0;
}
0