結果

問題 No.1233 割り切れない気持ち
ユーザー kk
提出日時 2021-03-22 10:51:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 478 ms / 3,153 ms
コード長 814 bytes
コンパイル時間 2,170 ms
コンパイル使用メモリ 205,052 KB
実行使用メモリ 6,388 KB
最終ジャッジ日時 2023-08-15 13:05:01
合計ジャッジ時間 8,540 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 75 ms
4,380 KB
testcase_08 AC 126 ms
4,376 KB
testcase_09 AC 260 ms
5,700 KB
testcase_10 AC 277 ms
5,644 KB
testcase_11 AC 60 ms
4,380 KB
testcase_12 AC 327 ms
6,136 KB
testcase_13 AC 306 ms
6,280 KB
testcase_14 AC 317 ms
6,388 KB
testcase_15 AC 333 ms
6,132 KB
testcase_16 AC 335 ms
6,176 KB
testcase_17 AC 17 ms
6,220 KB
testcase_18 AC 478 ms
6,200 KB
testcase_19 AC 25 ms
6,232 KB
testcase_20 AC 17 ms
6,164 KB
testcase_21 AC 26 ms
6,388 KB
testcase_22 AC 26 ms
6,136 KB
testcase_23 AC 26 ms
6,176 KB
testcase_24 AC 26 ms
6,388 KB
testcase_25 AC 27 ms
6,204 KB
testcase_26 AC 27 ms
6,284 KB
testcase_27 AC 30 ms
6,224 KB
testcase_28 AC 30 ms
6,220 KB
testcase_29 AC 29 ms
6,304 KB
testcase_30 AC 29 ms
6,176 KB
testcase_31 AC 29 ms
6,172 KB
testcase_32 AC 29 ms
6,216 KB
testcase_33 AC 29 ms
6,120 KB
testcase_34 AC 29 ms
6,220 KB
testcase_35 AC 28 ms
6,220 KB
testcase_36 AC 28 ms
6,308 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 28 ms
6,232 KB
testcase_39 AC 246 ms
6,216 KB
testcase_40 AC 245 ms
6,160 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  
  int n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];

  sort(a.begin(), a.end());
  
  vector<long long> pref(n + 1);
  for (int i = 0; i < n; i++)
    pref[i+1] = pref[i] + a[i];
  
  long long ret = 0;
  for (int i = 0; i < n; ) {
    int j = i;
    while (j < n && a[j] == a[i])
      ++j;
    long long x = pref[i];
    for (long long s = a[i]; s <= a[n-1]; s += a[i]) {
      long long t = s + a[i];
      int p = lower_bound(a.begin(), a.end(), s) - a.begin();
      int q = lower_bound(a.begin(), a.end(), t) - a.begin();
      x += (pref[q] - pref[p]) - (q - p) * s;
    }
    ret += (j - i) * x;
    i = j;
  }
  
  cout << ret << endl;
  
  return 0;
}
0