結果

問題 No.2260 Adic Sum
ユーザー ja14378ja14378
提出日時 2023-04-07 22:13:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 972 bytes
コンパイル時間 2,228 ms
コンパイル使用メモリ 206,508 KB
実行使用メモリ 78,876 KB
最終ジャッジ日時 2024-04-15 23:33:03
合計ジャッジ時間 20,427 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,624 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 6 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 5 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 7 ms
5,376 KB
testcase_13 AC 5 ms
5,376 KB
testcase_14 AC 67 ms
7,252 KB
testcase_15 AC 105 ms
8,872 KB
testcase_16 AC 56 ms
6,944 KB
testcase_17 AC 123 ms
9,472 KB
testcase_18 AC 1,786 ms
44,928 KB
testcase_19 AC 1,957 ms
47,616 KB
testcase_20 AC 1,312 ms
33,792 KB
testcase_21 AC 1,329 ms
34,304 KB
testcase_22 AC 1,111 ms
29,952 KB
testcase_23 AC 784 ms
21,504 KB
testcase_24 AC 1,920 ms
44,288 KB
testcase_25 AC 217 ms
12,672 KB
testcase_26 AC 207 ms
12,544 KB
testcase_27 AC 224 ms
12,928 KB
testcase_28 AC 210 ms
12,544 KB
testcase_29 AC 212 ms
12,544 KB
testcase_30 AC 285 ms
11,648 KB
testcase_31 AC 699 ms
14,848 KB
testcase_32 AC 663 ms
14,976 KB
testcase_33 AC 186 ms
13,696 KB
testcase_34 AC 540 ms
29,056 KB
testcase_35 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using ll = long long;
#define MOD 1000000007
#define Mod 998244353
const int MAX = 1000000005;
const long long INF = 1000000000000000005LL;
using namespace std;



int main() {
    ios::sync_with_stdio(0);cin.tie();
    int N, P;
    cin >> N >> P;
    vector<ll> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    ll now = 1;
    int M = 0;
    while (now < 1000000000) {
        M++;
        now *= P;
    }
    vector<map<int, int>> C(M+1);
    now = 1;
    for (int i = 0; i <= M; i++) {
        for (int j = 0; j < N; j++) C[i][A[j] % now]++;
        now *= P;
    }
    ll ans = 0;
    now = P;
    for (int i = 1; i < M; i++) {
        for (int j = 0; j < N; j++) {
            ans += (ll)i * (C[i][A[j] % now] - C[i+1][A[j] % (now * P)]);
            C[i][A[j] % now]--;
            C[i+1][A[j] % (now * P)]--;
        }
        for (int j = 0; j < N; j++) C[i+1][A[j] % (now * P)]++;
        now *= P;
    }
    cout << ans << endl;
}
0