QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#732392 | #5137. Tower | yumingsk# | WA | 1ms | 3712kb | C++20 | 2.6kb | 2024-11-10 14:21:06 | 2024-11-10 14:21:06 |
Judging History
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++)
{
// cout << b[i] << " "[i == (n - m)];
tmp_res += b[i];
}
// if (res > tmp_res)
// {
// // cout << mid << "s\n";
// }
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];
res = min(res, tmp_maxx);
tmp_maxx /= n;
tmp_maxx *= 2;
// cout << __lg(1) << ' ' << __lg(0) << '\n';
maxx = tmp_maxx;
// cout << tmp_maxx << '\n';
// for (int k = 0; k <= maxx; k++)
// {
// }
while (minn > 0)
{
int l = minn;
int r = minn + min(tmp_maxx, minn);
if (minn == a[1])
r = minn + tmp_maxx;
// cout << l << ' ' << r << '\n';
//--------------
for (int i = l; i <= r; i++)
{
check(i);
}
if (minn == 1)
break;
// cout << res << ' ' << tmp_maxx << '\n';
minn /= 2;
// tmp_maxx -= n;
}
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: -100
Wrong Answer
time: 1ms
memory: 3660kb
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 7 436 114 570 636 994 227 656 66
result:
wrong answer 2nd numbers differ - expected: '3', found: '7'