結果

問題 No.2709 1975 Powers
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2024-04-03 12:18:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 121 ms / 2,000 ms
コード長 1,168 bytes
コンパイル時間 2,253 ms
コンパイル使用メモリ 207,916 KB
実行使用メモリ 66,632 KB
最終ジャッジ日時 2024-04-03 12:18:44
合計ジャッジ時間 6,480 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 104 ms
65,860 KB
testcase_01 AC 104 ms
65,860 KB
testcase_02 AC 105 ms
66,632 KB
testcase_03 AC 114 ms
66,248 KB
testcase_04 AC 118 ms
66,504 KB
testcase_05 AC 116 ms
66,376 KB
testcase_06 AC 109 ms
66,120 KB
testcase_07 AC 105 ms
66,500 KB
testcase_08 AC 109 ms
66,632 KB
testcase_09 AC 121 ms
66,504 KB
testcase_10 AC 104 ms
66,500 KB
testcase_11 AC 104 ms
66,120 KB
testcase_12 AC 107 ms
66,632 KB
testcase_13 AC 116 ms
66,632 KB
testcase_14 AC 108 ms
66,248 KB
testcase_15 AC 108 ms
66,632 KB
testcase_16 AC 113 ms
66,248 KB
testcase_17 AC 106 ms
66,244 KB
testcase_18 AC 114 ms
66,632 KB
testcase_19 AC 119 ms
66,376 KB
testcase_20 AC 105 ms
66,632 KB
testcase_21 AC 109 ms
66,632 KB
testcase_22 AC 118 ms
66,632 KB
testcase_23 AC 118 ms
66,376 KB
testcase_24 AC 119 ms
66,248 KB
testcase_25 AC 119 ms
66,376 KB
testcase_26 AC 119 ms
66,504 KB
権限があれば一括ダウンロードができます

ソースコード

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