QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#238471 | #5137. Tower | tselmegkh# | WA | 638ms | 3616kb | C++17 | 1.7kb | 2023-11-04 16:49:01 | 2023-11-04 16:49:04 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve() {
int n, m;
cin >> n >> m;
vector<int> a(n);
for (int &i : a) cin >> i;
ll ans = 1e18;
for (int i = 0; i < 30; i++) {
vector<int> b(n), c(n);
int cnt = 0;
for (int j = 0; j < n; j++) {
int k = __lg(a[j]);
b[j] = k <= i ? a[j] : (a[j] >> (k - i));
if (k > i) cnt += k - i;
}
for (int j = 0; j < n; j++) {
for (int z = 0; z < 2; z++) {
int v = b[j] >> z;
if (v == 0) continue;
int c2 = cnt;
for (int k = 0; k < n; k++) {
if (b[k] / 2 == 0 || abs(b[k] - v) <= abs(b[k] / 2 - v)) {
c[k] = b[k];
} else {
c[k] = b[k] / 2;
c2++;
}
}
sort(c.begin(), c.end());
int p = -1;
vector<ll> s(n + 1);
for (int k = 0; k < n; k++) {
s[k + 1] = s[k] + c[k];
if (c[k] == v) p = k;
}
assert(p != -1);
for (int k = 0; k <= min(m, p); k++) {
if (m - k > n - p - 1) continue;
ans = min(ans, (s[n - m + k] - s[p + 1]) - (s[p] - s[k]) + 1LL * v * ((p - k) - ((n - m + k) - (p + 1))) + c2);
}
}
}
}
cout << ans << "\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3616kb
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: 638ms
memory: 3500kb
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:
596 3 561 151 831 662 1049 310 704 93
result:
wrong answer 1st numbers differ - expected: '454', found: '596'