結果

問題 No.2709 1975 Powers
ユーザー wanuiwanui
提出日時 2024-03-31 14:24:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 828 ms / 2,000 ms
コード長 1,816 bytes
コンパイル時間 2,362 ms
コンパイル使用メモリ 208,628 KB
実行使用メモリ 65,864 KB
最終ジャッジ日時 2024-03-31 14:24:56
合計ジャッジ時間 13,552 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 105 ms
65,860 KB
testcase_01 AC 105 ms
65,860 KB
testcase_02 AC 110 ms
65,864 KB
testcase_03 AC 500 ms
65,864 KB
testcase_04 AC 757 ms
65,864 KB
testcase_05 AC 563 ms
65,864 KB
testcase_06 AC 240 ms
65,864 KB
testcase_07 AC 105 ms
65,860 KB
testcase_08 AC 227 ms
65,864 KB
testcase_09 AC 563 ms
65,864 KB
testcase_10 AC 106 ms
65,860 KB
testcase_11 AC 116 ms
65,864 KB
testcase_12 AC 136 ms
65,864 KB
testcase_13 AC 583 ms
65,864 KB
testcase_14 AC 166 ms
65,864 KB
testcase_15 AC 174 ms
65,864 KB
testcase_16 AC 472 ms
65,864 KB
testcase_17 AC 106 ms
65,860 KB
testcase_18 AC 147 ms
65,864 KB
testcase_19 AC 766 ms
65,864 KB
testcase_20 AC 109 ms
65,864 KB
testcase_21 AC 242 ms
65,864 KB
testcase_22 AC 800 ms
65,864 KB
testcase_23 AC 806 ms
65,864 KB
testcase_24 AC 804 ms
65,864 KB
testcase_25 AC 822 ms
65,864 KB
testcase_26 AC 828 ms
65,864 KB
権限があれば一括ダウンロードができます

ソースコード

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());

    ll ans = 0;
    for (ll a = 0; a < N; a++) {
        ll asum = pow10[A[a]] % P;
        for (ll b = a + 1; b < N; b++) {
            ll bsum = (asum + pow9[A[b]]) % P;
            for (ll c = b + 1; c < N; c++) {
                ll csum = (bsum + pow7[A[c]]) % P;
                for (ll d = c + 1; d < N; d++) {
                    if ((csum + pow5[A[d]]) % P == Q) ans++;
                }
            }
        }
    }
    print1(ans);
    return 0;
}
0