結果

問題 No.2709 1975 Powers
ユーザー Tatsu_mrTatsu_mr
提出日時 2024-03-31 14:39:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,604 bytes
コンパイル時間 2,431 ms
コンパイル使用メモリ 212,880 KB
実行使用メモリ 88,160 KB
最終ジャッジ日時 2024-03-31 14:39:33
合計ジャッジ時間 6,608 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 160 ms
81,480 KB
testcase_01 AC 160 ms
81,480 KB
testcase_02 AC 215 ms
81,484 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

vector<long long> v = {10LL, 9LL, 7LL, 5LL};
int siz = 2000010;

long long modpow(long long a, long long b, long long mod) {
    long long cur = a, ans = 1;
    for (int i = 0; i < 60; i++) {
        if (b & (1LL << i)) {
            ans = (ans * cur) % mod;
        }
        cur = (cur * cur) % mod;
    }
    return ans;
}

int main() {
    int n;
    long long p, q;
    cin >> n >> p >> q;
    vector<long long> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    vector<vector<long long>> mods(4, vector<long long>(siz, 1LL));
    for (int i = 0; i < 4; i++) {
        for (int j = 1; j < siz; j++) {
            mods[i][j] = mods[i][j - 1] * v[i] % p;
        }
    }
    vector<char> c;
    for (int i = 0; i < 4; i++) {
        c.push_back('o');
    }
    for (int i = 0; i < n - 4; i++) {
        c.push_back('x');
    }
    sort(a.begin(), a.end());
    int ans = 0;
    do {
        long long res = 0LL;
        int w = -1, x = -1, y = -1, z = -1;
        for (int i = 0; i < n; i++) {
            if (c[i] == 'o') {
                if (w == -1) {
                    w = i;
                } else if (x == -1) {
                    x = i;
                } else if (y == -1) {
                    y = i;
                } else {
                    z = i;
                }
            }
        }
        res += (((mods[0][a[w]] + mods[1][a[x]]) % p + mods[2][a[y]]) % p + mods[3][a[z]]) % p;
        if (res == q) {
            ans++;
        }
    } while (next_permutation(c.begin(), c.end()));
    cout << ans << endl;
}
0