QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#497538 | #8723. 乘二 | ucup-team1883 | Compile Error | / | / | C++14 | 1006b | 2024-07-29 13:12:08 | 2024-07-29 13:12:09 |
Judging History
answer
#include <cstdio>
#include <queue>
using ll = long long;
const int N = 200005;
const int Mod = 1000000007;
int pow(int a, int b, int ans = 1);
int a[N];
int c[N];
int n, k;
int main() {
scanf("%d %d", &n, &k);
std::priority_queue<int, std::vector<int>, std::greater<int>> pq;
for (int i = 1; i <= n; ++i) {
scanf("%d", a + i);
pq.push(a[i]);
}
while (pq.top() <= Mod && k) {
int now = pq.top();
pq.pop();
--k;
pq.push(now * 2);
}
int top = 0;
while (!pq.empty()) {
a[++top] = pq.top();
pq.pop();
}
std::sort(a + 1, a + n + 1);
for (int i = 1; i <= n; ++i) c[i] = k / n;
k %= n;
for (int i = 1; i <= k; ++i) ++c[i];
int ans = 0;
for (int i = 1; i <= n; ++i) ans = (ans + 1ll * a[i] * pow(2, c[i])) % Mod;
printf("%d\n", ans);
return 0;
}
int pow(int a, int b, int ans) {
while (b) {
if (b & 1) ans = 1ll * ans * a % Mod;
a = 1ll * a * a % Mod;
b >>= 1;
}
return ans;
}
Details
answer.code: In function ‘int main()’: answer.code:32:8: error: ‘sort’ is not a member of ‘std’ 32 | std::sort(a + 1, a + n + 1); | ^~~~ answer.code:15:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 15 | scanf("%d %d", &n, &k); | ~~~~~^~~~~~~~~~~~~~~~~ answer.code:18:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 18 | scanf("%d", a + i); | ~~~~~^~~~~~~~~~~~~