結果

問題 No.2260 Adic Sum
ユーザー CoCo_Japan_panCoCo_Japan_pan
提出日時 2023-04-07 21:57:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,134 bytes
コンパイル時間 2,263 ms
コンパイル使用メモリ 204,224 KB
実行使用メモリ 15,156 KB
最終ジャッジ日時 2024-04-15 23:32:26
合計ジャッジ時間 4,702 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 19 ms
6,912 KB
testcase_15 AC 27 ms
8,496 KB
testcase_16 AC 17 ms
6,400 KB
testcase_17 AC 31 ms
8,776 KB
testcase_18 AC 72 ms
5,376 KB
testcase_19 WA -
testcase_20 AC 59 ms
5,376 KB
testcase_21 AC 60 ms
5,376 KB
testcase_22 AC 54 ms
5,376 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 50 ms
12,180 KB
testcase_26 AC 48 ms
12,084 KB
testcase_27 AC 50 ms
12,456 KB
testcase_28 AC 49 ms
12,188 KB
testcase_29 AC 48 ms
12,320 KB
testcase_30 AC 39 ms
5,888 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 32 ms
5,376 KB
testcase_34 AC 41 ms
5,376 KB
testcase_35 WA -
権限があれば一括ダウンロードができます

ソースコード

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;
int 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 += 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