結果

問題 No.1233 割り切れない気持ち
ユーザー yataro800yataro800
提出日時 2023-01-09 14:34:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 401 ms / 3,153 ms
コード長 1,481 bytes
コンパイル時間 4,992 ms
コンパイル使用メモリ 234,660 KB
実行使用メモリ 18,644 KB
最終ジャッジ日時 2023-08-22 17:47:26
合計ジャッジ時間 10,942 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 68 ms
5,976 KB
testcase_08 AC 120 ms
8,104 KB
testcase_09 AC 245 ms
12,024 KB
testcase_10 AC 263 ms
12,628 KB
testcase_11 AC 58 ms
5,692 KB
testcase_12 AC 309 ms
14,244 KB
testcase_13 AC 301 ms
14,140 KB
testcase_14 AC 301 ms
14,160 KB
testcase_15 AC 311 ms
14,136 KB
testcase_16 AC 315 ms
14,092 KB
testcase_17 AC 34 ms
6,244 KB
testcase_18 AC 401 ms
18,644 KB
testcase_19 AC 64 ms
6,324 KB
testcase_20 AC 34 ms
6,172 KB
testcase_21 AC 53 ms
6,272 KB
testcase_22 AC 53 ms
6,336 KB
testcase_23 AC 53 ms
6,244 KB
testcase_24 AC 52 ms
6,240 KB
testcase_25 AC 53 ms
6,256 KB
testcase_26 AC 53 ms
6,256 KB
testcase_27 AC 61 ms
6,328 KB
testcase_28 AC 61 ms
6,252 KB
testcase_29 AC 61 ms
6,336 KB
testcase_30 AC 60 ms
6,320 KB
testcase_31 AC 61 ms
6,296 KB
testcase_32 AC 62 ms
6,220 KB
testcase_33 AC 61 ms
6,240 KB
testcase_34 AC 61 ms
6,240 KB
testcase_35 AC 61 ms
6,236 KB
testcase_36 AC 61 ms
6,248 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 40 ms
6,172 KB
testcase_39 AC 206 ms
12,244 KB
testcase_40 AC 206 ms
12,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <math.h>

#include <algorithm>
#include <array>
#include <atcoder/all>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <vector>

using namespace std;
using namespace atcoder;

using Graph = vector<vector<int>>;

using ll = long long;
typedef pair<ll, ll> P_ll;
typedef pair<int, int> P;

const ll INF_ll = 1e17;
const int INF = 1e8;
template <class T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  sort(A.begin(), A.end());
  vector<ll> sumA(N + 1, 0);
  for (int i = 0; i < N; i++) {
    sumA[i + 1] = sumA[i] + A[i];
  }
  ll ans = 0;
  map<ll, ll> mp;
  for (int i = 0; i < N; i++) {
    if (mp.count(A[i]) > 0) {
      ans += mp[A[i]];
      continue;
    }
    ll prev = 0;
    ll tmp = 0;
    for (ll j = 1; (j - 1) * A[i] <= A.back(); j++) {
      ll id = lower_bound(A.begin(), A.end(), j * A[i]) - A.begin();
      tmp += (sumA[id] - sumA[prev]) - (j - 1) * A[i] * (id - prev);
      prev = id;
    }
    mp[A[i]] = tmp;
    ans += tmp;
    // cout << i << "," << ans << endl;
  }
  cout << ans << endl;

  return 0;
}
0