QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#421639#8723. 乘二NRWA 0ms3900kbC++142.5kb2024-05-25 23:19:542024-05-25 23:19:54

Judging History

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

  • [2024-05-25 23:19:54]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3900kb
  • [2024-05-25 23:19:54]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>

using namespace std;
typedef long long ll;
const int N=200010;
const ll mod=1e9+7;

struct node{
    ll a, n, mi, i;

}arr[N];

bool cmp(node a, node b){
    return a.a < b.a;
}


struct cmpmi
{
    //重载 () 运算符
    bool operator()(node a, node b)
    {
        int ai = -1, bi = -1;
        int da = a.a, db = b.a;
        while(da){
            ai ++;
            da = da & (da - 1);
        }
        while(db){
            bi ++;
            db = db & (db - 1);
        }
        if(ai == bi){
            return a.n > b.n;
        }
        else if(ai > bi){
            return a.n > b.n - (ai - bi);
        }
        else{
            return a.n - (bi - ai) > b.n;
        }
    }
};

int main(){
    int n, k;
    cin >> n >> k;
    priority_queue<node, vector<node>, cmpmi> que;
    for(int i = 1; i <= n; i ++){
        scanf("%lld", &arr[i].a);
    }

    sort(arr + 1, arr + n + 1, cmp);

    int maxx = arr[n].a, maxi = -1;
    while(maxx){
        maxi ++;
        maxx >>= 1;
    }
    que.push({arr[n].a, 0, 0, n});

    for(int i = 1; i < n; i ++){
        ll maxx = arr[n].a;
        ll tmp = arr[i].a;
        int cnt = 0;

        while(1 << maxi > tmp){
            cnt ++;
            tmp <<= 1;
            //cout << "?";
        }
        arr[i].mi = cnt;
        que.push({arr[i].a, arr[i].n, arr[i].mi, i});

    }
    // for(int i = 1; i <= n; i ++){
    //     cout << arr[i].mi << " ";
    // }cout << endl;
    int f = 0;
    while(k){
        auto toop = que.top();
        //cout << toop.a << " ";
        if(toop.mi == 0){
            f = 1;
            break;
        }

        que.pop();
        k --;
        toop.mi -= 1;
        toop.n += 1;
        arr[toop.i].n += 1;
        que.push(toop);

    }
    //k = k + 1;
    //cout << k << endl;
    if(k){
        int tk = k / n;
        k = k % n;
        for(int i = 1; i <= n; i ++){
            arr[i].n += tk;
            if(i <= k)arr[i].n += 1;
        }
    }

    ll ans = 0;
    for(int i = 1; i <= n; i ++){
        ll ai = arr[i].a, cnt = arr[i].n;

        ll tmp = 1, t = 2;
        while(cnt){
            if(cnt & 1){
                tmp = (tmp * t) % mod;
            }
            t = (t * t) % mod;
            cnt >>= 1;
        }

        tmp = (tmp * ai) % mod;
        cout << tmp << ' ';
        ans = (ans + tmp) % mod;
    }
    cout << ans;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3900kb

input:

3 3
7 2 1

output:

4 4 7 15

result:

wrong answer 1st numbers differ - expected: '15', found: '4'