結果

問題 No.2260 Adic Sum
ユーザー cumincumin
提出日時 2023-04-08 06:40:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,198 ms / 2,000 ms
コード長 3,874 bytes
コンパイル時間 5,049 ms
コンパイル使用メモリ 271,692 KB
実行使用メモリ 10,368 KB
最終ジャッジ日時 2024-04-15 23:59:45
合計ジャッジ時間 13,332 ms
ジャッジサーバーID
(参考情報)
judge1 / 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 2 ms
5,376 KB
testcase_08 AC 4 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 4 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
6,100 KB
testcase_15 AC 64 ms
7,296 KB
testcase_16 AC 32 ms
5,744 KB
testcase_17 AC 64 ms
7,424 KB
testcase_18 AC 713 ms
9,728 KB
testcase_19 AC 765 ms
10,240 KB
testcase_20 AC 505 ms
10,112 KB
testcase_21 AC 516 ms
10,112 KB
testcase_22 AC 427 ms
9,984 KB
testcase_23 AC 277 ms
10,240 KB
testcase_24 AC 720 ms
10,240 KB
testcase_25 AC 105 ms
9,728 KB
testcase_26 AC 98 ms
9,728 KB
testcase_27 AC 111 ms
10,112 KB
testcase_28 AC 103 ms
9,728 KB
testcase_29 AC 101 ms
9,856 KB
testcase_30 AC 97 ms
7,552 KB
testcase_31 AC 225 ms
8,064 KB
testcase_32 AC 223 ms
8,064 KB
testcase_33 AC 101 ms
10,368 KB
testcase_34 AC 236 ms
10,240 KB
testcase_35 AC 1,198 ms
10,240 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/extc++.h>
//#include<atcoder/all>
 
using namespace std;
//using namespace atcoder;

#define ll long long
#define ld long double
#define ull unsigned long long
#define _overload4(_1,_2,_3,_4,name,...) name
#define _overload3(_1,_2,_3,name,...) name
#define _rep1(n) for(ll i = 0; i < n; ++i)
#define _rep2(i, n) for(ll i = 0; i < n; ++i)
#define _rep3(i, a, b) for(ll i = a; i < b; ++i)
#define _rep4(i, a, b, c) for(ll i = a; i < b; i += c)
#define rep(...) _overload4(__VA_ARGS__, _rep4, _rep3, _rep2, _rep1)(__VA_ARGS__)
#define rrep(i, n) for(int i = (n)-1; i >= 0; i--)
#define rrep2(i, a, b) for(int i = (a)-1; i >= b; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
#define eb emplace_back
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pcc pair<char, char>
#define pdd pair<double, double>
#define endl '\n'
//using Bint = __int128_t;
template<class T> using pq = priority_queue< T >;
template<class T> using pqg = priority_queue< T , vector< T >, greater< T >>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>
T ceil_div(T a, T b) {
    if(b < 0) a = -a, b = -b;
    return (a >= 0 ? (a + b - 1) / b : a / b);
}
 
template<class T>
T floor_div(T a, T b) {
    if(b < 0) a = -a, b = -b;
    return (a >= 0 ? a / b : (a - b + 1) / b);
}
inline ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll digit(ll x){
  string s = to_string(x);
  return (ll)s.size();
}

const int inf = 1001001001;
const ll INF = 1001001001001001001;

const double PI = acos(-1);

bool range(ll y, ll x, ll h, ll w){
  return (0 <= y && y < h && 0 <= x && x < w);
}
int dy[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
int dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};

//using mint = modint998244353;
//const int MOD = 998244353;
//using mint = modint1000000007;
const int MOD = 1000000007;

template<class T> vector< T > compress(vector< T > a){
  auto b = a;
  sort(b.begin(), b.end());
  b.erase(unique(b.begin(), b.end()), b.end());
  int n = a.size();
  for(auto& x : a) x = lower_bound(b.begin(), b.end(), x) - b.begin();
  return a;
}
pair<vector<int>, vector<int>> bfs(vector<vector<int>> &G, int s){
  int n = G.size();
  vector<int> dist(n, inf);
  vector<int> from(n, -1);
  dist[s] = 0;
  queue<int> que;
  que.push(s);
  while(!que.empty()){
    int v = que.front();
    que.pop();
    for(int nv : G[v]){
      if(dist[nv] != inf) continue;
      dist[nv] = dist[v] + 1;
      from[nv] = v;
      que.push(nv);
    }
  }
  return {dist, from};
}
ll modpow(ll a, ll n, ll mod){
  if(n == 0)return 1;
  if(n%2 == 0){
    ll t = modpow(a, n/2, mod);
    return (t*t)%mod;
  }
  return a*modpow(a, n-1, mod)%mod;
}
pair<vector<ll>, vector<int>> dijkstra(vector<vector<pll>> &G, int s){
  int n = G.size();
  vector<ll> dist(n, INF);
  vector<int> prev(n, -1);
  dist[s] = 0;
  pqg<pll> que;
  que.push({0, s});
  while(!que.empty()){
    auto[c, v] = que.top();
    que.pop();
    if(dist[v] != c) continue;
    for(auto[nv, add] : G[v]){
      if(dist[nv] > dist[v] + add){
        dist[nv] = dist[v] + add;
        prev[nv] = v;
        que.push({dist[nv], nv});
      }
    }
  }
  return {dist, prev};
}
void Yes(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
}
signed main(){

  cout << fixed << setprecision(15);
  
  int n;
  ll p;
  cin >> n >> p;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  
  ll ans = 0;
  ll pp = p;
  while(pp < 1e9 + 2){
    map<ll, ll> mp;
    rep(i, n){
      ans += mp[a[i]%pp];
      mp[a[i]%pp]++;
    }
    pp *= p;
  }
  
  
  cout << ans << endl;
  return 0;
}
0