Submission #60763883
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(),(v).end()
#define pb(a) push_back(a)
#define rep(i, n) for(int i=0;i<n;i++)
#define foa(e, v) for(auto&& e : v)
using ll = long long;
const ll MOD7 = 1000000007, MOD998 = 998244353, INF = (1LL << 60);
#define dout(a) cout<<fixed<<setprecision(10)<<a<<endl;
ll solve(vector<ll> tmp) {
ll ans = 0;
vector<pair<vector<ll>, vector<ll>>> v;
{
vector<ll> v1, v2;
int n = tmp.size();
rep(i, n) {
if(tmp[i] & 1) v1.pb(tmp[i]);
else v2.pb(tmp[i]);
}
ll sz = v1.size();
ans += sz * (sz - 1) / 2;
ans += accumulate(all(v1), 0LL) * (sz - 1);
sz = v2.size();
ans += sz * (sz - 1) / 2;
ans += accumulate(all(v2), 0LL) * (sz - 1);
v.push_back({v1, v2});
}
while(!v.empty()) {
auto [v1, v2] = v.back();
v.pop_back();
if(v1.empty() or v2.empty()) continue;
for(ll &x : v1) x /= 2;
for(ll &x : v2) x /= 2;
vector<ll> nx1, nx2, nx3, nx4;
foa(x, v1) {
if(x & 1) nx1.pb(x);
else nx2.pb(x);
}
foa(x, v2) {
if(x & 1) nx3.pb(x);
else nx4.pb(x);
}
{
ll sz1 = nx1.size();
ll sz2 = nx3.size();
ans += sz1 * sz2;
ans += sz1 * accumulate(all(nx3), 0LL);
ans += sz2 * accumulate(all(nx1), 0LL);
}
{
ll sz1 = nx2.size();
ll sz2 = nx4.size();
ans += sz1 * sz2;
ans += sz1 * accumulate(all(nx4), 0LL);
ans += sz2 * accumulate(all(nx2), 0LL);
}
v.push_back({nx1, nx4});
v.push_back({nx2, nx3});
}
return ans;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll n;
cin >> n;
vector<ll> a(n);
ll ans = 0;
rep(i, n) {
cin >> a[i];
{
ll x = a[i] * 2;
while(x % 2 == 0) x /= 2;
ans += x;
}
}
while(!a.empty()) {
if(accumulate(all(a), 0LL) == 0LL) break;
n = a.size();
vector<ll> v0, v1;
rep(i, n) {
if(a[i] & 1) v1.pb(a[i]);
else v0.pb(a[i]);
}
ans += accumulate(all(v1), 0LL) * (ll)v0.size();
ans += accumulate(all(v0), 0LL) * (ll)v1.size();
int sz = v0.size();
rep(i, sz) v0[i] >>= 1;
sz = n - sz;
rep(i, sz) v1[i] >>= 1;
ans += solve(v1);
swap(a, v0);
}
cout << ans << endl;
return 0;
}
Submission Info
| Submission Time |
|
| Task |
F - Double Sum 2 |
| User |
shinchan |
| Language |
C++ 20 (gcc 12.2) |
| Score |
500 |
| Code Size |
2703 Byte |
| Status |
AC |
| Exec Time |
100 ms |
| Memory |
13504 KiB |
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
500 / 500 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt |
| All |
00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_handmade_00.txt, 01_handmade_01.txt, 01_handmade_02.txt, 01_handmade_03.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 02_random_11.txt, 02_random_12.txt, 02_random_13.txt, 02_random_14.txt, 02_random_15.txt, 02_random_16.txt |
| Case Name |
Status |
Exec Time |
Memory |
| 00_sample_00.txt |
AC |
1 ms |
3432 KiB |
| 00_sample_01.txt |
AC |
1 ms |
3436 KiB |
| 00_sample_02.txt |
AC |
1 ms |
3496 KiB |
| 01_handmade_00.txt |
AC |
37 ms |
11552 KiB |
| 01_handmade_01.txt |
AC |
23 ms |
11616 KiB |
| 01_handmade_02.txt |
AC |
16 ms |
11060 KiB |
| 01_handmade_03.txt |
AC |
10 ms |
6668 KiB |
| 02_random_00.txt |
AC |
89 ms |
9860 KiB |
| 02_random_01.txt |
AC |
89 ms |
9704 KiB |
| 02_random_02.txt |
AC |
89 ms |
9612 KiB |
| 02_random_03.txt |
AC |
89 ms |
10008 KiB |
| 02_random_04.txt |
AC |
89 ms |
9620 KiB |
| 02_random_05.txt |
AC |
12 ms |
5584 KiB |
| 02_random_06.txt |
AC |
88 ms |
9896 KiB |
| 02_random_07.txt |
AC |
88 ms |
13504 KiB |
| 02_random_08.txt |
AC |
100 ms |
9936 KiB |
| 02_random_09.txt |
AC |
99 ms |
9848 KiB |
| 02_random_10.txt |
AC |
97 ms |
9256 KiB |
| 02_random_11.txt |
AC |
99 ms |
9688 KiB |
| 02_random_12.txt |
AC |
97 ms |
9372 KiB |
| 02_random_13.txt |
AC |
18 ms |
11112 KiB |
| 02_random_14.txt |
AC |
20 ms |
10124 KiB |
| 02_random_15.txt |
AC |
20 ms |
10548 KiB |
| 02_random_16.txt |
AC |
21 ms |
7684 KiB |