結果

問題 No.1233 割り切れない気持ち
ユーザー vjudge1
提出日時 2025-08-15 15:28:17
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
TLE  
実行時間 -
コード長 791 bytes
コンパイル時間 1,551 ms
コンパイル使用メモリ 161,492 KB
実行使用メモリ 12,324 KB
最終ジャッジ日時 2025-08-15 15:28:48
合計ジャッジ時間 30,975 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 36 TLE * 1 -- * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define ll long long

using namespace std;

const int MAXN = 2e5 + 5, MAXV = 2e5 + 5;

int n, a[MAXN], cnt[MAXV];
ll ans;

int main(){
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n;
  for(int i = 1; i <= n; i++){
    cin >> a[i];
    cnt[a[i]]++;
  }
  sort(a + 1, a + 1 + n);
  for(int i = a[n]; i >= 1; i--){
    cnt[i] += cnt[i + 1];
  }
  for(int i = 1; i <= n; i++){
    ans += 1ll * a[i] * n;
  }
  for(int i = 1; i <= n; i++){
    bool f = 0;
    for(int j = a[i]; j <= a[n]; j += a[i]){
      int p1 = lower_bound(a + 1, a + 1 + n, j) - a, p2 = (!f ? lower_bound(a + 1, a + 1 + n, j + a[i]) - a : 0);
      f |= (p2 == n + 1);
      if(a[p1] - j < a[i]){
        ans -= 1ll * j * (cnt[a[p1]] - cnt[a[p2]]);
      }
    }
  }
  cout << ans;
  return 0;
}
0