QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#732197#5137. Toweryumingsk#WA 8ms3596kbC++202.1kb2024-11-10 13:38:422024-11-10 13:38:43

Judging History

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

  • [2024-11-10 13:38:43]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:3596kb
  • [2024-11-10 13:38:42]
  • 提交

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++)
    {
        if (a[i] <= mid)
        {
            b[i] = mid - a[i];
        }
        else
        {
            b[i] = a[i] - mid;
            int tmp = a[i];
            int cnt = 0;
            while (tmp >= mid)
            {
                b[i] = min(tmp - mid + cnt, b[i]);
                tmp /= 2;
                cnt++;
            }
            b[i] = min(b[i], mid - tmp + cnt);
        }
    }
    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 - m; i++)
    {
        tmp_maxx += __lg(a[i]);
    }
    minn = a[1];
    // cout << __lg(8) << ' ' << __lg(9) << '\n';
    maxx = 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);
        }
        minn /= 2;
    }
    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;
}

詳細信息

Test #1:

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

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: -100
Wrong Answer
time: 8ms
memory: 3596kb

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
5
436
108
570
636
994
227
656
50

result:

wrong answer 2nd numbers differ - expected: '3', found: '5'