結果

問題 No.2709 1975 Powers
ユーザー srjywrdnprkt
提出日時 2024-04-03 12:18:37
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 124 ms / 2,000 ms
コード長 1,168 bytes
コンパイル時間 2,299 ms
コンパイル使用メモリ 199,624 KB
最終ジャッジ日時 2025-02-20 19:50:36
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    ll N, M=2e6, P, Q, ans=0, a, b, c, d;
    cin >> N >> P >> Q;
    vector<ll> p10(M+1), p9(M+1), p7(M+1), p5(M+1);
    p10[0] = 1;
    p9[0] = 1;
    p7[0] = 1;
    p5[0] = 1;
    for (int i=1; i<=M; i++){
        p10[i] = p10[i-1] * 10;
        p10[i] %= P;
        p9[i] = p9[i-1] * 9;
        p9[i] %= P;
        p7[i] = p7[i-1] * 7;
        p7[i] %= P;
        p5[i] = p5[i-1] * 5;
        p5[i] %= P;
    }

    vector<ll> mp(P);
    vector<ll> A(N+1);
    for (int i=1; i<=N; i++) cin >> A[i];
    sort(A.begin(), A.end());

    mp[p10[A[1]]]++;
    for (int i=2; i<=N; i++){
        for (int j=i+1; j<=N; j++){
            for (int k=j+1; k<=N; k++){
                a = p9[A[i]];
                b = p7[A[j]];
                c = p5[A[k]];
                //(a+b+c+d) % P = Q;
                // x = Q-(a+b+c) % P
                d = (Q-(a+b+c)) % P;
                if (d < 0) d += P;
                ans += mp[d];
            }
        }
        mp[p10[A[i]]]++;
    }

    cout << ans << endl;

    return 0;
}
0