結果

問題 No.2709 1975 Powers
ユーザー blue_jamblue_jam
提出日時 2024-03-31 14:06:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,686 ms / 2,000 ms
コード長 1,289 bytes
コンパイル時間 4,629 ms
コンパイル使用メモリ 272,584 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-31 14:07:28
合計ジャッジ時間 23,967 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 40 ms
6,676 KB
testcase_03 AC 961 ms
6,676 KB
testcase_04 AC 1,437 ms
6,676 KB
testcase_05 AC 1,076 ms
6,676 KB
testcase_06 AC 433 ms
6,676 KB
testcase_07 AC 3 ms
6,676 KB
testcase_08 AC 409 ms
6,676 KB
testcase_09 AC 1,062 ms
6,676 KB
testcase_10 AC 4 ms
6,676 KB
testcase_11 AC 68 ms
6,676 KB
testcase_12 AC 148 ms
6,676 KB
testcase_13 AC 1,103 ms
6,676 KB
testcase_14 AC 239 ms
6,676 KB
testcase_15 AC 300 ms
6,676 KB
testcase_16 AC 889 ms
6,676 KB
testcase_17 AC 11 ms
6,676 KB
testcase_18 AC 181 ms
6,676 KB
testcase_19 AC 1,425 ms
6,676 KB
testcase_20 AC 27 ms
6,676 KB
testcase_21 AC 397 ms
6,676 KB
testcase_22 AC 1,675 ms
6,676 KB
testcase_23 AC 1,686 ms
6,676 KB
testcase_24 AC 1,678 ms
6,676 KB
testcase_25 AC 1,678 ms
6,676 KB
testcase_26 AC 1,679 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;
using namespace atcoder;

using ll = long long;

ll mod_pow(ll n, ll k, ll m) {
    ll res = 1;
    while (k > 0) {
        if (k & 1) {
            res = res * n % m;
        }
        n = n * n % m;
        k >>= 1;
    }
    return res;
}

int main() {
    ll N, P, Q;
    cin >> N >> P >> Q;
    vector<ll> A(N);
    for (ll i = 0; i < N; i++) {
        cin >> A[i];
    }
    sort(A.begin(), A.end());

    map<ll, vector<ll>> mp;

    for (auto a: A) {
        ll r = mod_pow(5, a, P);
        mp[r].push_back(a);
    }
    for (auto& [k, v]: mp) {
        sort(v.begin(), v.end());
    }

    ll ans = 0;
    for (ll i = 0; i < N; i++) {
        for (ll j = i + 1; j < N; j++) {
            for (ll k = j + 1; k < N; k++) {
                ll s = (mod_pow(10, A[i], P) +
                        mod_pow(9, A[j], P) +
                        mod_pow(7, A[k], P)) % P;
                ll t = (Q - s + P) % P;
                if (mp.find(t) == mp.end()) {
                    continue;
                }
                auto& v = mp[t];
                auto it = lower_bound(v.begin(), v.end(), A[k] + 1);
                ans += v.end() - it;
            }
        }
    }
    cout << ans << endl;

    return 0;
}
0