QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#732601#9599. Dragon BloodlinekazimiyuukaWA 277ms4276kbC++202.7kb2024-11-10 15:17:402024-11-10 15:17:42

Judging History

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

  • [2024-11-10 15:17:42]
  • 评测
  • 测评结果:WA
  • 用时:277ms
  • 内存:4276kb
  • [2024-11-10 15:17:40]
  • 提交

answer

#include <iostream>
#include <string>
#include <string.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <random>
#include <cstdlib>
#include <numeric>
#include <functional>
#include <queue>
#include <stdlib.h>
#include <map>
using namespace std;
using ll = long long;
ll mod = 1e9 + 7;

void slove() {
    ll n, k;
    cin >> n >> k;


    vector<ll> ned(n + 1);
    vector<ll> pri(k + 1);
    vector<ll> bac(k + 1);
    for (int i = 1; i <= n; i++) cin >> ned[i];
    for (int i = 0; i < k; i++) cin >> pri[i];
    bac = pri;

    vector<ll> tmp(k + 1);
    function<void()> rev = [&]() {
        for (int i = 0; i <= k; i++) {
            pri[i] += tmp[i];
            tmp[i] = 0;
        }
    };

    //int h = k;

    //function<void()> nUp = [&]() {
    //    while (h >= 0 && !pri[h]) h--;
    //};

    //function<bool(ll)> cal = [&](ll val) {
    //    nUp();
    //    for (int i = h; i >= 0; i--) {
    //        
    //        if (val <= (1LL << i)) break;
    //        
    //        if (val > (1LL << i) * pri[i]) {
    //            val -= (1LL << i) * pri[i];
    //            pri[i] = 0;
    //        }
    //        else {
    //            pri[i] -= (val) / (1LL << i);
    //            val %= (1LL << i);
    //            break;
    //        }
    //    }
    //};

    function<bool(ll)> judge = [&](ll tar) {
        pri = bac;
        priority_queue<ll ,vector<ll> , less<ll>> q;
        for (int i = 1; i <= n; i++) {
            q.emplace(ned[i] * tar);
        }

        for (int i = k; i >= 0; i--) {
            ll val = 1LL << i;
            while (pri[i] && !q.empty()) {
                auto ptr = q.top();
                q.pop();

                if (ptr < val) pri[i]--;
                else {
                    ll cnt = min(ptr / val, pri[i]);
                    ptr -= cnt * val;
                    pri[i] -= cnt;
                    if (ptr) q.emplace(ptr);
                }
            }
        }

        if (q.empty()) {
            return true;
        }
        return false;

        //for (int i = 1; i <= n; i++) {
        //    ll t = ned[i] * tar;
        //    if (!cal(t)) 
        //        return false;
        //}
        //return true;
    };

    ll l = 0, r = 1e18;
    while (l < r) {
        ll mid = (l + r) / 2 + 1;
        
        if (judge(mid)) l = mid;
        else r = mid - 1;
    }


    cout << l << "\n";
}



int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);

    int cnt = 1;
    cin >> cnt;
    while (cnt--) {
        slove();
    }
    return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

6
4 3
1 2 3 4
4 4 4
3 2
1 1 1
1 7
3 4
6 6 2
1 1 5 5
3 5
3 1 1
1 1 1 1 1
4 5
1 9 9 8
2 2 2 3 1
5 4
1 3 1 7 1
4 1 5 2

output:

2
4
4
5
2
3

result:

ok 6 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 3564kb

input:

1
1 20
1
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000

output:

1048575000000000

result:

ok single line: '1048575000000000'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3864kb

input:

2
3 2
1 1 1
1 7
4 2
1 1 1 1
1 2

output:

4
0

result:

ok 2 lines

Test #4:

score: 0
Accepted
time: 277ms
memory: 4276kb

input:

1
50000 20
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

1048575

result:

ok single line: '1048575'

Test #5:

score: -100
Wrong Answer
time: 28ms
memory: 3616kb

input:

1000
37 20
2 8 8 7 8 7 4 6 7 4 7 4 8 4 4 5 8 3 5 5 7 7 10 6 3 2 5 3 5 8 3 6 2 4 7 3 3
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
9 12
4 7 12 6 12 18 11 35 19
3 8 2 6 3 6 4 3 8 4 4 9
26 13
9 9 5 3 4 5 2 10 4 6 6 9 5 3 9 10 6 2 10 4 2 9 9 3 9 3
1 1 1 1 1 1 1 1 1 1 1 1 1
33 18
3 5 3 3 4 1 4 3 1 4 5 1 3 4 ...

output:

0
222
0
18103
0
0
0
12
0
90
0
77
4
0
78
4
5
18
0
576460752303423508
0
47
0
0
2307
85
0
571
352
16
0
39
1
21
0
1
0
0
5631
795
0
231
0
0
1615
0
0
0
0
0
91
0
5
9
13
264
493
156
0
0
29
0
8191
0
138
0
1
0
0
62526843532062340
100
0
0
136
98
160
0
0
3
149
0
0
250125343372354036
0
0
10532
2437
0
0
1
52
50
0...

result:

wrong answer 20th lines differ - expected: '11', found: '576460752303423508'