QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#558656 | #5137. Tower | shabi666# | WA | 79ms | 3648kb | C++14 | 1.8kb | 2024-09-11 17:26:27 | 2024-09-11 17:26:28 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
#define endl "\n"
using namespace std;
//using ll = long long;
const int N = 505;
pair<int, int> arr[N];
int sum[N];
int cnt[N];
void solve(){
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> arr[i].first;
}
sort(arr + 1, arr + n + 1);
int ans = INT_MAX;
int len = n - m;
do {
memset(sum, 0, sizeof sum);
memset(cnt, 0, sizeof cnt);
for (int i = 1; i <= n; i++) {
sum[i] = sum[i - 1] + arr[i].first;
cnt[i] = cnt[i - 1] + arr[i].second;
}
int p1 = 0, p2 = 0;
for (int l = 1, r = len; r <= n; l++, r++) {
int idx = (r - l + 1) / 2;
int cur = arr[idx].first;
int len1 = len / 2;
int len2 = len - len1;
ans = min(ans, cnt[r] - cnt[l - 1] + (sum[r] - sum[idx] - len2 * cur) + (cur * len1 - sum[idx] + sum[l - 1]));
}
arr[n].first /= 2;
arr[n].second++;
sort(arr + 1, arr + n + 1);
// cout << ans << endl;
// for (int i = 1; i <= n; i++) {
// cout << arr[i].first << " ";
// }
// cout << endl;
// for (int i = 1; i <= n; i++) {
// cout << arr[i].second << " ";
// }
// cout << endl;
} while (arr[n].first != 1);
memset(cnt, 0, sizeof cnt);
for (int i = 1; i <= n; i++) {
cnt[i] = cnt[i - 1] + arr[i].second;
}
ans = min(ans, cnt[n]);
cout << ans << endl;
memset(sum, 0, sizeof sum);
memset(cnt, 0, sizeof cnt);
memset(arr, 0, sizeof arr);
}
signed main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int T = 1;
cin >> T;
while (T--) {
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3648kb
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: 79ms
memory: 3644kb
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:
477 9 448 122 630 637 1022 234 665 74
result:
wrong answer 1st numbers differ - expected: '454', found: '477'