QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#679320 | #5137. Tower | blue_sky | WA | 6ms | 3616kb | C++20 | 1.5kb | 2024-10-26 17:22:37 | 2024-10-26 17:22:39 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
#define x first
#define y second
#define bug(X) cout << "bug:# " << X << endl
#define bug2(f, X) cout << "bug:# " << f << " " << X << endl
#define bug3(i, j, G) cout << "bug:# " << i << ' ' << j << ' ' << G << endl
#define endl '\n'
using namespace std;
const int mod = 998244353;
const int N = 10 + 5e5;
void _();
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
cin >> t;
while (t--)
_();
return 0;
}
void _()
{
int n, m;
cin >> n >> m;
vector<int> a(n);
map<int, int> tar;
for (int i = 0; i < n; i++)
{
int x;
cin >> x;
a[i] = x;
while (x)
{
tar[x] = 1;
x >>= 1;
}
}
auto get = [](int st, int ed)
{
if (st <= ed)
return ed - st;
int ans = 0;
while (st > ed && st / 2 > 0)
{
ans++;
st >>= 1;
}
if (st < ed)
ans += min(ed - st, st * 2 - ed );
else
ans += st - ed;
return ans;
};
int res = 1e18;
for (auto [x, _] : tar)
{
vector<int> ans(n);
for (int i = 0; i < n; i++)
ans[i] = get(a[i], x);
int tans = 0;
sort(ans.begin(), ans.end());
for (int i = 0; i < n - m; i++)
tans += ans[i];
res = min(res, tans);
}
cout << res << endl;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3580kb
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: 6ms
memory: 3616kb
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:
466 3 441 116 587 649 1025 229 664 55
result:
wrong answer 1st numbers differ - expected: '454', found: '466'