結果

問題 No.2709 1975 Powers
ユーザー ryota2357ryota2357
提出日時 2024-03-31 01:33:37
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,317 bytes
コンパイル時間 923 ms
コンパイル使用メモリ 121,196 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-31 01:33:45
合計ジャッジ時間 8,069 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;

long long pow_mod(long long x, long long n, long long mod) {
    long long ret = 1;
    while (n > 0) {
        if (n & 1) {
            ret *= x;
        }
        x *= x;
        x %= mod;
        n >>= 1;
    }
    return ret;
}

int main() {
    int n, p, q;
    cin >> n >> p >> q;
    assert(4 <= n && n <= 200);
    assert(2 <= q && q < p && p <= 100000);
    vector<int> a(n);
    for (int i = 0; i < n; ++i) { cin >> a[i]; }
    for (int i = 0; i < n; ++i) { assert(1 <= a[i] && a[i] <= 2000000); }
    sort(a.begin(), a.end());

    vector<int> m10(n), m9(n), m7(n), m5(n);
    for (int i = 0; i < n; ++i) {
        m10[i] = pow_mod(10, a[i], p);
        m9[i] = pow_mod(9, a[i], p);
        m7[i] = pow_mod(7, a[i], p);
        m5[i] = pow_mod(5, a[i], p);
    }

    int 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) {
                    long long sum = m10[i] + m9[j] + m7[k] + m5[l];
                    if (sum % p == q) {
                        ans += 1;
                    }
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}
0