結果

問題 No.2260 Adic Sum
ユーザー suisui
提出日時 2023-04-08 05:28:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,206 ms / 2,000 ms
コード長 1,355 bytes
コンパイル時間 4,896 ms
コンパイル使用メモリ 263,052 KB
実行使用メモリ 71,680 KB
最終ジャッジ日時 2024-04-15 23:59:19
合計ジャッジ時間 12,697 ms
ジャッジサーバーID
(参考情報)
judge2 / 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 2 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 38 ms
7,296 KB
testcase_15 AC 56 ms
8,960 KB
testcase_16 AC 32 ms
6,912 KB
testcase_17 AC 61 ms
9,292 KB
testcase_18 AC 641 ms
44,544 KB
testcase_19 AC 698 ms
47,400 KB
testcase_20 AC 478 ms
33,664 KB
testcase_21 AC 471 ms
33,920 KB
testcase_22 AC 398 ms
29,568 KB
testcase_23 AC 257 ms
20,992 KB
testcase_24 AC 658 ms
44,160 KB
testcase_25 AC 108 ms
12,340 KB
testcase_26 AC 102 ms
12,304 KB
testcase_27 AC 115 ms
12,672 KB
testcase_28 AC 107 ms
12,300 KB
testcase_29 AC 108 ms
12,552 KB
testcase_30 AC 87 ms
9,472 KB
testcase_31 AC 161 ms
12,800 KB
testcase_32 AC 162 ms
12,800 KB
testcase_33 AC 88 ms
13,312 KB
testcase_34 AC 135 ms
19,072 KB
testcase_35 AC 1,206 ms
71,680 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n+1); i++)
#define repn(i,a,b) for (int i = (int)(a) ; i < (int)(b+1); i++)
#define repv(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x) ((int)(x).size())
#define uni(v) v.erase(unique(v.begin(), v.end()), v.end());
using ll = long long;
using P = pair<int,int>;
using mint = modint998244353;
ostream& operator<< (ostream& os, const mint &x) {os << x.val(); return os;}
#ifdef LOCAL
    #include <debug.hpp>
    #define debug(...) debug::multi_print(#__VA_ARGS__, __VA_ARGS__)
#else
    #define debug(...) (static_cast<void>(0))
#endif


int main(){
    int n,p;
    cin >> n >> p;
    vector<int> a(n);
    for(auto &x : a) cin >> x;
    vector<map<int,int>> amari;
    ll powp = p, max_a = *max_element(all(a));
    while(powp <= max_a){
        map<int,int> mp;
        for(auto x : a){
            mp[x % powp]++;
        }
        amari.push_back(mp);
        powp *= p;
    }

    ll ans = 0;
    for(int i = 0; i < sz(amari); i++){
        for(auto p: amari[i]){
            ans += ((ll)p.second*(p.second-1)/2);
        }
    }
    cout << ans << endl;
    return 0;
}
0