QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#602527#8723. 乘二ucup-team902#RE 0ms0kbC++141.3kb2024-10-01 10:17:262024-10-01 10:17:28

Judging History

你现在查看的是最新测评结果

  • [2024-10-01 10:17:28]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-10-01 10:17:26]
  • 提交

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();
    }
}

詳細信息

Test #1:

score: 0
Runtime Error

input:

3 3
7 2 1

output:


result: