結果

問題 No.2260 Adic Sum
ユーザー ruthen71ruthen71
提出日時 2023-04-07 21:34:41
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,884 ms / 2,000 ms
コード長 763 bytes
コンパイル時間 2,114 ms
コンパイル使用メモリ 213,212 KB
実行使用メモリ 88,576 KB
最終ジャッジ日時 2024-10-06 07:07:08
合計ジャッジ時間 11,908 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#ifdef _RUTHEN
#include <debug.hpp>
#else
#define show(...) true
#endif

using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
template <class T> using V = vector<T>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    long long N, P;
    cin >> N >> P;
    V<long long> A(N);
    rep(i, N) cin >> A[i];
    V<long long> B;
    long long c = 1;
    while (c <= 1000000000LL / P) {
        B.push_back(c * P);
        c *= P;
    }
    show(B);
    int K = B.size();
    long long ans = 0;
    V<map<long long, int>> r(K);
    rep(i, N) {
        rep(j, K) {
            ans += r[j][A[i] % B[j]];
            r[j][A[i] % B[j]]++;
        }
    }
    cout << ans << '\n';
    return 0;
}
0