結果
問題 |
No.1233 割り切れない気持ち
|
ユーザー |
![]() |
提出日時 | 2025-08-15 15:36:22 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 491 ms / 3,153 ms |
コード長 | 899 bytes |
コンパイル時間 | 1,729 ms |
コンパイル使用メモリ | 165,488 KB |
実行使用メモリ | 6,272 KB |
最終ジャッジ日時 | 2025-08-15 15:36:31 |
合計ジャッジ時間 | 7,351 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 39 |
ソースコード
#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); 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; }