QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#732819#5137. Toweryumingsk#Compile Error//C++202.3kb2024-11-10 15:59:582024-11-10 16:00:00

Judging History

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

  • [2024-11-10 16:00:00]
  • 评测
  • [2024-11-10 15:59:58]
  • 提交

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;
#define int 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; 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

cc1plus: error: ‘::main’ must return ‘int’