結果

問題 No.2046 Ans Mod? Mod Ans!
ユーザー SSRSSSRS
提出日時 2022-08-19 21:41:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 420 ms / 4,000 ms
コード長 792 bytes
コンパイル時間 2,135 ms
コンパイル使用メモリ 171,220 KB
実行使用メモリ 5,340 KB
最終ジャッジ日時 2023-08-22 11:39:47
合計ジャッジ時間 4,541 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,376 KB
testcase_01 AC 4 ms
4,380 KB
testcase_02 AC 9 ms
4,376 KB
testcase_03 AC 35 ms
4,380 KB
testcase_04 AC 22 ms
4,376 KB
testcase_05 AC 35 ms
4,504 KB
testcase_06 AC 24 ms
4,380 KB
testcase_07 AC 33 ms
4,376 KB
testcase_08 AC 6 ms
4,380 KB
testcase_09 AC 8 ms
4,376 KB
testcase_10 AC 8 ms
4,380 KB
testcase_11 AC 11 ms
4,380 KB
testcase_12 AC 10 ms
4,380 KB
testcase_13 AC 147 ms
4,376 KB
testcase_14 AC 115 ms
4,376 KB
testcase_15 AC 216 ms
4,380 KB
testcase_16 AC 232 ms
4,492 KB
testcase_17 AC 184 ms
4,376 KB
testcase_18 AC 242 ms
4,376 KB
testcase_19 AC 174 ms
4,376 KB
testcase_20 AC 420 ms
5,340 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