結果

問題 No.2709 1975 Powers
ユーザー ynishi2015ynishi2015
提出日時 2024-03-31 14:55:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 327 ms / 2,000 ms
コード長 1,279 bytes
コンパイル時間 972 ms
コンパイル使用メモリ 81,816 KB
実行使用メモリ 39,712 KB
最終ジャッジ日時 2024-03-31 14:55:24
合計ジャッジ時間 7,145 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
39,712 KB
testcase_01 AC 117 ms
39,712 KB
testcase_02 AC 121 ms
39,712 KB
testcase_03 AC 226 ms
39,712 KB
testcase_04 AC 294 ms
39,712 KB
testcase_05 AC 247 ms
39,712 KB
testcase_06 AC 157 ms
39,712 KB
testcase_07 AC 119 ms
39,712 KB
testcase_08 AC 156 ms
39,712 KB
testcase_09 AC 239 ms
39,712 KB
testcase_10 AC 120 ms
39,712 KB
testcase_11 AC 124 ms
39,712 KB
testcase_12 AC 129 ms
39,712 KB
testcase_13 AC 243 ms
39,712 KB
testcase_14 AC 138 ms
39,712 KB
testcase_15 AC 139 ms
39,712 KB
testcase_16 AC 214 ms
39,712 KB
testcase_17 AC 119 ms
39,712 KB
testcase_18 AC 130 ms
39,712 KB
testcase_19 AC 293 ms
39,712 KB
testcase_20 AC 121 ms
39,712 KB
testcase_21 AC 153 ms
39,712 KB
testcase_22 AC 322 ms
39,712 KB
testcase_23 AC 327 ms
39,712 KB
testcase_24 AC 322 ms
39,712 KB
testcase_25 AC 322 ms
39,712 KB
testcase_26 AC 322 ms
39,712 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>

std::vector<int> ints(int size) {
    std::vector<int> result(size);
    for (int& i : result) {
        std::cin >> i;
    }
    return result;
}

int main() {
    int N, P, Q;
    std::cin >> N >> P >> Q;
    std::vector<int> A = ints(N);
    std::sort(A.begin(), A.end());

    const int AMAX = 2000010;
    std::vector<int> n10(1, 1), n9(1, 1), n7(1, 1), n5(1, 1);

    int p = 1;
    for (int i = 0; i < AMAX; ++i) {
        p = (p * 10) % P;
        n10.push_back(p);
    }

    p = 1;
    for (int i = 0; i < AMAX; ++i) {
        p = (p * 9) % P;
        n9.push_back(p);
    }

    p = 1;
    for (int i = 0; i < AMAX; ++i) {
        p = (p * 7) % P;
        n7.push_back(p);
    }

    p = 1;
    for (int i = 0; i < AMAX; ++i) {
        p = (p * 5) % P;
        n5.push_back(p);
    }

    int cnt = 0;
    for (int a = 0; a < N; ++a) {
        for (int b = a + 1; b < N; ++b) {
            for (int c = b + 1; c < N; ++c) {
                for (int d = c + 1; d < N; ++d) {
                    if ((n10[A[a]] + n9[A[b]] + n7[A[c]] + n5[A[d]]) % P == Q) {
                        ++cnt;
                    }
                }
            }
        }
    }

    std::cout << cnt << std::endl;

    return 0;
}
0