結果

問題 No.2709 1975 Powers
ユーザー wanui
提出日時 2024-03-31 15:22:47
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 224 ms / 2,000 ms
コード長 1,851 bytes
コンパイル時間 2,068 ms
コンパイル使用メモリ 211,656 KB
最終ジャッジ日時 2025-02-20 17:52:19
ジャッジサーバーID
(参考情報)
judge3 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
// clang-format off
using namespace std; using ll=long long; using ull=unsigned long long; using pll=pair<ll,ll>; const ll INF=4e18;
void print0(){}; template<typename H,typename... T> void print0(H h,T... t){cout<<h;print0(t...);}
void print1(){print0("\n");}; template<typename H,typename... T>void print1(H h,T... t){print0(h);if(sizeof...(T)>0)print0(" ");print1(t...);}
void ioinit() { cout<<fixed<<setprecision(15); cerr<<fixed<<setprecision(6); ios_base::sync_with_stdio(0); cin.tie(0); }
#define debug1(a) { cerr<<#a<<":"<<a<<endl; }
#define debug2(a,b) { cerr<<#a<<":"<<a<<" "<<#b<<":"<<b<<endl; }
#define debug3(a,b,c) { cerr<<#a<<":"<<a<<" "<<#b<<":"<<b<<" "<<#c<<":"<<c<<endl; }
#define debug4(a,b,c,d) { cerr<<#a<<":"<<a<<" "<<#b<<":"<<b<<" "<<#c<<":"<<c<<" "<<#d<<":"<<d<<endl; }
// clang-format on

int main() {
    ioinit();
    ll N, P, Q;
    cin >> N >> P >> Q;

    vector<ll> pow10(2000001, 1);
    vector<ll> pow9(2000001, 1);
    vector<ll> pow7(2000001, 1);
    vector<ll> pow5(2000001, 1);
    for (ll i = 1; i <= 2000000; i++) {
        pow10[i] = pow10[i - 1] * 10 % P;
        pow9[i] = pow9[i - 1] * 9 % P;
        pow7[i] = pow7[i - 1] * 7 % P;
        pow5[i] = pow5[i - 1] * 5 % P;
    }
    vector<ll> A(N);
    for (ll i = 0; i < N; i++) {
        cin >> A[i];
    }
    sort(A.begin(), A.end());

    vector<map<ll, ll>> mp(N);
    map<ll, ll> cnt;
    for (ll c = N - 1; c >= 0; c--) {
        for (ll d = c + 1; d < N; d++) {
            ll m = (pow7[A[c]] + pow5[A[d]]) % P;
            cnt[m]++;
        }
        mp[c] = cnt;
    }

    ll ans = 0;
    for (ll a = 0; a < N; a++) {
        for (ll b = a + 1; b < N; b++) {
            ll m = (pow10[A[a]] + pow9[A[b]]) % P;
            if (b + 1 < N) ans += mp[b + 1][(Q - m + P) % P];
        }
    }

    print1(ans);
    return 0;
}
0