QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#602527 | #8723. 乘二 | ucup-team902# | RE | 0ms | 0kb | C++14 | 1.3kb | 2024-10-01 10:17:26 | 2024-10-01 10:17:28 |
answer
#include <bits/stdc++.h>
using namespace std;
multiset<int> a[40];
const int mod = 1e9 + 7;
long long qpow(long long x, long long y) {
long long res = 1;
while (y) {
if (y & 1) res = res * x % mod;
x = x * x % mod;
y >>= 1;
}
return res;
}
void solve() {
int n, k;
cin >> n >> k;
for (int i = 1; i <= n; ++i) {
int x;
cin >> x;
a[__lg(x)].insert(x);
}
int ans = 0;
for (int i = 0; i <= 29; ++i) {
for (auto now = a[i].begin(); k && now != a[i].end(); ++now) {
k--;
a[i + 1].insert(2 * (*now));
a[i].erase(now);
}
}
if (k == 0) {
for (int i = 0; i <= 30; ++i) {
for (int v : a[i]) ans = (ans + v) % mod;
}
} else {
int len = a[30].size();
int pre = k / len;
int nxt = k % len;
for (auto i = a[30].begin(); i != a[30].end(); ++i) {
if (nxt != 0) {
nxt--;
ans = (ans + 1ll * (*i) * qpow(2, pre + 1) % mod) % mod;
} else {
ans = (ans + 1ll * (*i) * qpow(2, pre) % mod) % mod;
}
}
}
cout << ans << endl;
}
int main() {
ios::sync_with_stdio(false);
int T = 1;
while (T--) {
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
3 3 7 2 1