結果

問題 No.2260 Adic Sum
ユーザー mtrhmtrh
提出日時 2023-04-07 22:10:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,049 bytes
コンパイル時間 2,636 ms
コンパイル使用メモリ 214,208 KB
実行使用メモリ 50,304 KB
最終ジャッジ日時 2024-04-15 23:54:41
合計ジャッジ時間 15,177 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 4 ms
5,376 KB
testcase_13 AC 4 ms
5,376 KB
testcase_14 AC 37 ms
6,528 KB
testcase_15 AC 55 ms
8,064 KB
testcase_16 AC 33 ms
6,400 KB
testcase_17 AC 68 ms
8,448 KB
testcase_18 AC 1,147 ms
38,144 KB
testcase_19 AC 1,234 ms
40,320 KB
testcase_20 AC 727 ms
32,512 KB
testcase_21 AC 741 ms
32,768 KB
testcase_22 AC 601 ms
30,080 KB
testcase_23 AC 257 ms
12,160 KB
testcase_24 AC 966 ms
19,840 KB
testcase_25 AC 94 ms
11,136 KB
testcase_26 AC 90 ms
11,264 KB
testcase_27 AC 96 ms
11,520 KB
testcase_28 AC 94 ms
11,264 KB
testcase_29 AC 94 ms
11,392 KB
testcase_30 AC 97 ms
9,088 KB
testcase_31 AC 1,148 ms
50,304 KB
testcase_32 AC 1,144 ms
50,304 KB
testcase_33 AC 122 ms
12,160 KB
testcase_34 AC 339 ms
30,464 KB
testcase_35 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
    int N;
    ll P;
    cin >> N >> P;
    vector<ll> A(N);
    vector<pair<int, ll>> B(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        int k = 0;
        while (A[i] % P == 0) {
            k++;
            A[i] /= P;
        }
        B[i] = {k, A[i]};
    }
    sort(B.begin(), B.end());
    ll ans = 0;
    vector<map<ll, int>> mp;
    ll now = 1;
    while (now < 1e9) {
        map<ll, int> tmp;
        mp.push_back(tmp);
        now *= P;
    }
    ll prek = -1;
    for (int i = 0; i < N; i++) {
        ll k = B[i].first, m = B[i].second;
        ans += k * (N - i - 1);
        if (k != prek) {
            for (int i = 0; i < mp.size(); i++) {
                mp[i].clear();
            }
        }
        ll p = P;
        int j = 0;
        while (p < 1e9) {
            ans += mp[j][m % p];
            mp[j][m % p]++;
            j++;
            p *= P;
        }
        prek = k;
    }
    cout << ans << endl;
    return 0;
}
0