結果
問題 | No.1233 割り切れない気持ち |
ユーザー |
|
提出日時 | 2020-09-18 22:11:41 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 32 ms / 3,153 ms |
コード長 | 1,073 bytes |
コンパイル時間 | 1,597 ms |
コンパイル使用メモリ | 168,680 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-22 19:16:26 |
合計ジャッジ時間 | 3,656 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 39 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; constexpr char newl = '\n'; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin >> n; vector<ll> cnt(200010, 0); for (int i = 0; i < n; i++) { int a; cin >> a; ++cnt[a]; } // 0 1 2 3 0 0 0 0 // 0 1 1 1 -3 0 0 0 // 0 1 0 0 -4 3 0 0 ll ans = 0, memo = cnt[1]; vector<ll> dp(200010, 0); for (int i = 2; i <= 200000; i++) { if (!cnt[i]) continue; ans += memo * cnt[i]; for (int j = i; j <= 200000; j += i) { dp[j + 1] += cnt[i]; if (j + i <= 200000) dp[j + i] -= i * cnt[i]; if (j + i + 1 <= 200000) dp[j + i + 1] += (i - 1) * cnt[i]; } memo += cnt[i] * i; } for (int i = 1; i <= 200000; i++) { dp[i] += dp[i - 1]; } for (int i = 1; i <= 200000; i++) { dp[i] += dp[i - 1]; } for (int i = 0; i <= 200000; i++) { ans += dp[i] * cnt[i]; } cout << ans << newl; return 0; }