結果

問題 No.2260 Adic Sum
ユーザー CoCo_Japan_panCoCo_Japan_pan
提出日時 2023-04-07 21:59:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 121 ms / 2,000 ms
コード長 1,137 bytes
コンパイル時間 2,298 ms
コンパイル使用メモリ 206,268 KB
実行使用メモリ 15,156 KB
最終ジャッジ日時 2024-04-15 23:52:35
合計ジャッジ時間 4,747 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 3 ms
6,944 KB
testcase_14 AC 19 ms
6,940 KB
testcase_15 AC 28 ms
8,492 KB
testcase_16 AC 16 ms
6,940 KB
testcase_17 AC 30 ms
8,776 KB
testcase_18 AC 72 ms
6,944 KB
testcase_19 AC 77 ms
6,944 KB
testcase_20 AC 60 ms
6,940 KB
testcase_21 AC 60 ms
6,940 KB
testcase_22 AC 53 ms
6,944 KB
testcase_23 AC 48 ms
6,940 KB
testcase_24 AC 81 ms
6,940 KB
testcase_25 AC 56 ms
12,216 KB
testcase_26 AC 49 ms
12,084 KB
testcase_27 AC 53 ms
12,328 KB
testcase_28 AC 51 ms
12,224 KB
testcase_29 AC 53 ms
12,444 KB
testcase_30 AC 39 ms
6,940 KB
testcase_31 AC 120 ms
15,156 KB
testcase_32 AC 121 ms
15,156 KB
testcase_33 AC 32 ms
6,940 KB
testcase_34 AC 42 ms
6,944 KB
testcase_35 AC 107 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// 提出時にassertはオフ
#ifndef DEBUG
#ifndef NDEBUG
#define NDEBUG
#endif
#endif

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

#define ALL(x) (x).begin(), (x).end()
template <class T> using vec = vector<T>;

int N, P;
ll ans = 0;

// 同じmodPの集合に対し、そのmodを引いて、Pで割る
void groupByModP(const vec<int> &A) {
    if(A.size() <= 1) return;
    int curMod = A[0] % P;
    unordered_map<int, vec<int>> newGroup;
    for(int num : A) {
        int newNum = num + P - curMod;
        assert(newNum % P == 0);
        newNum /= P;
        newGroup[newNum % P].push_back(newNum);
    }
    ans += (ll)A.size() * (A.size() - 1) / 2;
    for(const pair<int, vec<int>> &p : newGroup) {
        groupByModP(p.second);
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N >> P;
    vec<int> A(N);
    for(int &a : A) cin >> a;
    unordered_map<int, vec<int>> group;
    for(int num : A) {
        group[num % P].push_back(num);
    }
    for(const pair<int, vec<int>> &p : group) {
        groupByModP(p.second);
    }
    cout << ans << "\n";
}
0