QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#732375 | #5137. Tower | yumingsk# | WA | 1ms | 3604kb | C++20 | 2.5kb | 2024-11-10 14:14:53 | 2024-11-10 14:14:54 |
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];
// cout << __lg(1) << ' ' << __lg(0) << '\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 + min(tmp_maxx, minn);
// 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;
}
詳細信息
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: 1ms
memory: 3604kb
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:
534 8 475 141 699 709 1135 228 729 88
result:
wrong answer 1st numbers differ - expected: '454', found: '534'