結果

問題 No.2046 Ans Mod? Mod Ans!
ユーザー SSRSSSRS
提出日時 2022-08-19 21:41:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 403 ms / 4,000 ms
コード長 792 bytes
コンパイル時間 1,701 ms
コンパイル使用メモリ 173,808 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-09 17:20:03
合計ジャッジ時間 4,080 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 4 ms
6,944 KB
testcase_02 AC 8 ms
6,944 KB
testcase_03 AC 32 ms
6,940 KB
testcase_04 AC 21 ms
6,940 KB
testcase_05 AC 32 ms
6,944 KB
testcase_06 AC 22 ms
6,940 KB
testcase_07 AC 29 ms
6,940 KB
testcase_08 AC 7 ms
6,940 KB
testcase_09 AC 6 ms
6,940 KB
testcase_10 AC 7 ms
6,940 KB
testcase_11 AC 11 ms
6,944 KB
testcase_12 AC 9 ms
6,944 KB
testcase_13 AC 137 ms
6,944 KB
testcase_14 AC 107 ms
6,940 KB
testcase_15 AC 204 ms
6,944 KB
testcase_16 AC 221 ms
6,940 KB
testcase_17 AC 183 ms
6,944 KB
testcase_18 AC 230 ms
6,944 KB
testcase_19 AC 165 ms
6,940 KB
testcase_20 AC 403 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  sort(A.begin(), A.end());
  vector<long long> S(N + 1);
  S[0] = 0;
  for (int i = 0; i < N; i++){
    S[i + 1] = S[i] + A[i];
  }
  long long ans = 0;
  for (int i = 0; i < N; i++){
    ans += (long long) A[i] * (N - 1 - i);
    for (int j = A[i]; j <= 200000; j += A[i]){
      int L;
      if (j == A[i]){
        L = lower_bound(A.begin(), A.end(), j + 1) - A.begin();
      } else {
        L = lower_bound(A.begin(), A.end(), j) - A.begin();
      }
      int R = lower_bound(A.begin(), A.end(), j + A[i]) - A.begin();
      if (L < R){
        ans -= S[R] - S[L] - (long long) (R - L) * j;
      }
    }
  }
  cout << ans << endl;
}
0