結果

問題 No.1233 割り切れない気持ち
ユーザー vjudge1
提出日時 2025-08-15 15:35:40
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 967 bytes
コンパイル時間 1,674 ms
コンパイル使用メモリ 165,652 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-08-15 15:35:44
合計ジャッジ時間 3,653 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 2
other WA * 39
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:13:10: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   13 |   freopen("mod.in", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
main.cpp:14:10: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   14 |   freopen("mod.out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

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], sum[MAXV];
ll ans;

int main(){
  ios::sync_with_stdio(0), cin.tie(0);
  freopen("mod.in", "r", stdin);
  freopen("mod.out", "w", stdout);
  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--){
    sum[i] = sum[i + 1] + cnt[i];
  }
  for(int i = 1; i <= n; i++){
    ans += 1ll * a[i] * n;
  }
  n = unique(a + 1, a + 1 + n) - a - 1;
  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(f){
        p2 = 0;
      }
      if(a[p1] - j < a[i]){
        ans -= 1ll * cnt[a[i]] * j * (sum[a[p1]] - sum[a[p2]]);
      }
    }
  }
  cout << ans;
  return 0;
}
0