QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#238155#5137. Towertselmegkh#WA 7ms3632kbC++171.1kb2023-11-04 15:55:482023-11-04 15:55:49

Judging History

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

  • [2023-11-04 15:55:49]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:3632kb
  • [2023-11-04 15:55:48]
  • 提交

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);
        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;
        }
        sort(b.begin(), b.end());
        if (b[0] == 0) continue;
        vector<ll> s(n + 1);
        for (int j = 0; j < n; j++) {
            s[j + 1] = s[j] + b[j];
        }
        for (int j = 0; j < n; j++) {
            for (int k = 0; k <= min(m, j); k++) {
                if (m - k > n - j - 1) continue;
                ans = min(ans, (s[n - m + k] - s[j + 1]) - (s[j] - s[k]) + 1LL * b[j] * ((j - k) - ((n - m + k) - (j + 1))) + cnt);
            }
        }
    }
    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: 3604kb

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: 7ms
memory: 3632kb

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:

578
3
560
149
802
671
1049
309
705
88

result:

wrong answer 1st numbers differ - expected: '454', found: '578'