結果
| 問題 |
No.1233 割り切れない気持ち
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-09-18 22:07:19 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,001 bytes |
| コンパイル時間 | 1,499 ms |
| コンパイル使用メモリ | 168,568 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-22 16:53:51 |
| 合計ジャッジ時間 | 3,710 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 11 WA * 28 |
ソースコード
#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 1 2 3
// 0 1 1 1 -3 1 1 1
// 0 1 0 0 -4 4 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];
}
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;
}