結果

問題 No.2709 1975 Powers
ユーザー hatsuka_iwahatsuka_iwa
提出日時 2024-03-31 15:33:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 345 ms / 2,000 ms
コード長 855 bytes
コンパイル時間 2,266 ms
コンパイル使用メモリ 210,516 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-31 15:33:10
合計ジャッジ時間 6,630 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 4 ms
6,676 KB
testcase_03 AC 167 ms
6,676 KB
testcase_04 AC 276 ms
6,676 KB
testcase_05 AC 186 ms
6,676 KB
testcase_06 AC 59 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 55 ms
6,676 KB
testcase_09 AC 187 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 7 ms
6,676 KB
testcase_12 AC 16 ms
6,676 KB
testcase_13 AC 197 ms
6,676 KB
testcase_14 AC 28 ms
6,676 KB
testcase_15 AC 33 ms
6,676 KB
testcase_16 AC 149 ms
6,676 KB
testcase_17 AC 2 ms
6,676 KB
testcase_18 AC 20 ms
6,676 KB
testcase_19 AC 272 ms
6,676 KB
testcase_20 AC 3 ms
6,676 KB
testcase_21 AC 53 ms
6,676 KB
testcase_22 AC 327 ms
6,676 KB
testcase_23 AC 345 ms
6,676 KB
testcase_24 AC 327 ms
6,676 KB
testcase_25 AC 327 ms
6,676 KB
testcase_26 AC 327 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
  int N, P, Q, C = 0; cin >> N >> P >> Q;
  vector<int> A(N); for (int &a : A) cin >> a; 
  vector B(4, vector<int>(N));
  sort(A.begin(), A.end());

  auto pow = [&](long long x, long long n) {
    long long ret = 1;
    while (n) {
      if (n & 1) ret = ret * x % P;
      x = x * x % P;
      n = n >> 1;
    }
    return ret;
  };

  for (int i = 0; i < N; i++) {
    B.at(0).at(i) = pow(10, A.at(i));
    B.at(1).at(i) = pow(9, A.at(i));
    B.at(2).at(i) = pow(7, A.at(i));
    B.at(3).at(i) = pow(5, A.at(i));
  }

  for (int i = 0; i < N - 3; i++)
    for (int j = i + 1; j < N - 2; j++)
      for (int k = j + 1; k < N - 1; k++)
        for (int l = k + 1; l < N; l++)
          if ((B.at(0).at(i) + B.at(1).at(j) + B.at(2).at(k) + B.at(3).at(l)) % P == Q) C++;

  cout << C << endl;
}
0