QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#418749#8723. 乘二mingqian_233#WA 107ms9240kbC++141.8kb2024-05-23 15:31:322024-05-23 15:31:34

Judging History

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

  • [2024-05-23 15:31:34]
  • 评测
  • 测评结果:WA
  • 用时:107ms
  • 内存:9240kb
  • [2024-05-23 15:31:32]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
#define pii pair<int, int>
using namespace std;
const int mod = 1e9 + 7;
int f_pow(int x, int y) {
    if (y == 1) return x;
    if (y == 0) return 1;
    int t = f_pow(x, y / 2) % mod;
    if (y % 2)
        return t * t % mod * x % mod;
    else
        return t * t % mod;
}
struct node {
    int val, mi, mult;
    int left;
};
bool cmp1(const node x, const node y) {
    return x.val < y.val;
}
bool cmp2(const node x, const node y) {
    return log2(double(x.left)) + x.mult < log2(double(y.left)) + y.mult;
}
signed main() {
    // ios::sync_with_stdio(false);
    // cin.tie(0);
    // cout.tie(0);
    int n, k, tot = 0;
    cin >> n >> k;
    vector<node> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i].val;
        a[i].mi = log2(a[i].val);
        a[i].left = a[i].val - (1<<a[i].mi);
        // printf("val:%lld mi:%lld left:%lld\n", a[i].val, a[i].mi, a[i].left);
        tot += a[i].mi;
    }
    int ava = (tot + k) / n;
    sort(a.begin(), a.end(), cmp1);
    int m;
    for (m = n - 1; m >= 0; m--) {
        ava = (tot + k) / (m + 1);
        tot -= a[m].mi;
        if (a[m].mi < ava) break;
    }
    for (int i = 0; i <= m; i++) {
        a[i].mult = ava - a[i].mi;
        k -= a[i].mult;
    }
    sort(a.begin(), a.begin() + m + 1, cmp2);
    for (int i = 0; i <= m; i++) {
        if (k == 0) break;
        a[i].mult++;
        k--;
    }
    // puts("mult:");
    // for (int i = 0; i <= m; i++) cout << a[i].val << ' ' << a[i].mult << '\n';
    int ans = 0;
    // printf("\nnums:\n");
    for (int i = 0; i < n; i++) {
        a[i].val = a[i].val * f_pow(2, a[i].mult) % mod;
        // cout << a[i].val << ' ';
        ans = (ans + a[i].val) % mod;
    }
    // puts("");
    cout << ans % mod;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3812kb

input:

3 3
7 2 1

output:

15

result:

ok 1 number(s): "15"

Test #2:

score: -100
Wrong Answer
time: 107ms
memory: 9240kb

input:

200000 1605067
366760624 67854 93901 693975 27016 1046 10808 6533158 54778 500941023 77236442 32173 10431454 2 9726 1553148 89282 411182309 494073 131299543 249904771 7906930 353 9909 3632698 29156 1917186 303 737 1189004 22 1983 263 711 4106258 2070 36704 12524642 5192 123 2061 22887 66 380 1 10153...

output:

792201632

result:

wrong answer 1st numbers differ - expected: '707034173', found: '792201632'