QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#732720#5137. Toweryumingsk#TL 5868ms3712kbC++202.2kb2024-11-10 15:41:212024-11-10 15:41:21

Judging History

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

  • [2024-11-10 15:41:21]
  • 评测
  • 测评结果:TL
  • 用时:5868ms
  • 内存:3712kb
  • [2024-11-10 15:41:21]
  • 提交

answer



#pragma GCC optimize(3, "Ofast", "inline")
#include <iostream>
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define INF 0x3f3f3f3f
#define L_INF 0x7f3f3f3f3f3f3f3f
#define db cout << "debug\n";

using namespace std;
const int Mod = 998244353;
using ll = long long;
int maxx = 1e9;
int n, m;
int a[505];
int res = 1e9;
int b[505];
void check(int mid)
{

    for (int i = 1; i <= n; i++)
    {
        b[i] = INF;
        if (a[i] <= mid)
        {
            b[i] = mid - a[i];
        }
        else
        {
            int cnt = 0;
            int tmp = a[i];

            while (tmp)
            {
                b[i] = min(b[i], abs(mid - tmp) + cnt);
                cnt++;
                tmp /= 2;
            }
        }
    }
    sort(b + 1, b + 1 + n);
    int tmp_res = 0;
    for (int i = 1; i <= n - m; i++)
        tmp_res += b[i];
    res = min(tmp_res, res);
}
void solve()
{
    cin >> n >> m;
    maxx = 1e9;
    res = 1e9;
    int tmp_maxx = 0;
    int minn = 2e9;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        // cout << __lg(a[i]) << '\n ';
    }
    sort(a + 1, a + 1 + n);
    for (int i = 1; i <= n; i++)
    {
        tmp_maxx += __lg(a[i]);
    }
    minn = a[1];
    // cout << __lg(8) << ' ' << __lg(9) << '\n';
    maxx = tmp_maxx;
    res = min(res, tmp_maxx);
    // cout << tmp_maxx << '\n';
    // for (int k = 0; k <= maxx; k++)
    // {
    // }
    while (minn > 0)
    {
        int l = minn;
        int r = minn + tmp_maxx;
        //--------------
        for (int i = l; i <= r; i++)
        {
            check(i);
        }
        if (minn == 1)
            break;
        // cout << res << ' ' << tmp_maxx << '\n';
        minn = 1;
    }
    cout << res << '\n';
}
int main()
{
    IOS;
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
#ifndef ONLINE_JUDGE
    clock_t start_time = clock();
#endif
    int t = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }
#ifndef ONLINE_JUDGE
    // cout << "Used " << (double)(clock() - start_time) << " ms" << endl;
#endif
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
2 0
2 6
5 0
1 2 3 4 5
5 3
1 2 3 4 5

output:

2
4
1

result:

ok 3 number(s): "2 4 1"

Test #2:

score: 0
Accepted
time: 15ms
memory: 3656kb

input:

10
272 118
11 14 49 94 71 62 46 45 74 22 15 36 7 37 27 35 96 85 75 78 76 64 23 59 17 35 71 28 96 82 5 66 2 48 57 31 88 10 61 73 79 23 19 52 39 76 48 98 5 39 48 51 90 90 60 27 47 24 24 56 48 27 39 21 38 18 20 9 62 83 47 15 51 22 73 74 7 80 64 60 86 74 59 7 84 38 99 31 42 60 52 41 63 88 59 90 77 40 68...

output:

454
3
436
108
570
636
994
227
656
50

result:

ok 10 numbers

Test #3:

score: 0
Accepted
time: 12ms
memory: 3592kb

input:

10
133 89
20 70 6 45 4 72 38 7 18 1 82 39 69 85 5 36 1 62 30 47 68 55 7 41 7 42 7 61 11 82 2 80 80 93 29 30 42 58 73 26 99 67 60 94 61 46 47 54 44 50 35 88 61 17 23 97 90 28 16 47 75 35 28 14 42 63 26 40 95 58 26 25 26 83 93 56 17 27 7 90 91 28 53 49 47 84 55 52 11 34 14 74 40 65 84 32 99 46 1 21 31...

output:

88
1361
128
246
29
83
3
677
96
382

result:

ok 10 numbers

Test #4:

score: 0
Accepted
time: 55ms
memory: 3612kb

input:

10
500 50
67 93 11 58 54 40 37 3 92 96 91 20 46 5 21 43 3 2 7 47 27 81 14 53 86 21 46 51 86 22 42 14 52 38 42 25 34 29 84 42 43 96 11 100 27 60 48 15 13 69 58 16 14 58 17 94 8 71 39 38 25 37 100 58 99 56 65 84 94 63 25 34 13 73 83 83 69 60 70 15 15 90 7 11 88 69 13 26 99 28 16 97 32 40 76 62 41 5 9 ...

output:

1608
169
144
983
1087
1317
882
75
32
1259

result:

ok 10 numbers

Test #5:

score: 0
Accepted
time: 212ms
memory: 3652kb

input:

10
500 414
503 505 103 380 946 153 952 386 890 306 522 147 499 784 643 121 264 344 549 72 299 314 45 688 97 747 442 528 752 830 335 78 159 218 748 331 259 375 479 883 202 402 595 738 430 184 874 762 864 743 733 209 821 616 868 543 314 161 100 638 439 943 732 962 243 776 803 423 749 367 731 594 993 9...

output:

338
2653
2857
809
1626
332
1328
490
1044
854

result:

ok 10 numbers

Test #6:

score: 0
Accepted
time: 1569ms
memory: 3652kb

input:

10
500 497
4249 4173 5055 5942 4090 1754 1523 5273 758 3522 8827 3775 6331 2729 8699 8797 5977 5435 6320 9188 5889 6562 9809 7595 6104 7480 2116 8715 2823 1990 425 5811 3347 2618 6119 3948 7172 7095 8017 5943 2036 87 6661 2099 885 3035 3745 8362 3919 2675 1314 8123 7254 328 106 2546 7540 9303 4333 9...

output:

1
2260
3254
4965
2322
2422
4862
1174
3671
877

result:

ok 10 numbers

Test #7:

score: 0
Accepted
time: 2928ms
memory: 3656kb

input:

10
500 425
62346 35359 49386 37821 13178 34961 89198 87150 5961 67958 2778 83160 89447 17663 63690 96481 48566 27701 64933 35987 44454 52207 22761 72984 57775 88898 28120 4798 93898 2808 185 49754 67340 4153 38477 14377 97568 57830 78927 11857 44320 71781 62631 7685 42960 80182 69195 31752 95159 311...

output:

762
548
2235
505
1333
5729
5820
3724
4260
2803

result:

ok 10 numbers

Test #8:

score: 0
Accepted
time: 4915ms
memory: 3664kb

input:

10
500 343
3979933 4977754 3585357 8727522 1167921 850266 4372205 6136332 1208124 9005074 1888230 1818841 5532232 8097244 9323282 2862526 1081283 5639323 3113788 3478923 6969022 3572708 8591079 9223149 25281 7629530 7701175 2406412 8085960 4273048 6252416 7216852 310879 1781062 1016170 6154578 21346...

output:

2803
0
1172
7122
9860
7880
7326
5368
1348
1133

result:

ok 10 numbers

Test #9:

score: 0
Accepted
time: 5868ms
memory: 3660kb

input:

10
500 337
8020609 91599948 284472 11014859 43731772 94734724 12907680 35883604 79976518 69620407 40667149 80019777 13205478 88987382 56851734 57312628 86016653 88153839 57436370 11777363 52281260 97911489 94737731 32588013 32104751 52267758 97646175 98939956 72977817 75964526 12807784 72438205 6797...

output:

3472
4278
5012
368
11069
4964
2159
9322
7802
7665

result:

ok 10 numbers

Test #10:

score: -100
Time Limit Exceeded

input:

10
500 399
42649299 961565652 731155387 495426036 927067195 429839645 335971489 846530637 913519418 120090307 242077430 62797226 117328086 261085207 332119648 917622458 982277579 237456542 108626001 724449186 247397791 193474848 886441482 245912131 547396118 454298309 959881298 690112275 996868401 4...

output:


result: