QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#781007 | #8679. Tilting Tiles | ucup-team5217 | WA | 0ms | 3636kb | C++23 | 1.1kb | 2024-11-25 14:23:23 | 2024-11-25 14:23:23 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define maxn 10005
int a[maxn];
int64_t f[2][maxn];
void solve(void) {
int n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++) cin >> a[i];
sort(a + 1, a + n + 1);
f[0][n] = 0;
bool t = 0;
int64_t ans = INT64_MAX;
for (int len = n;; len -= k - 1, t ^= true) {
if (len <= k) {
for (int l = 1, r = min(len, n); r <= n; l++, r++) ans = min(ans, f[t][r] + a[r]);
break;
}
for (int r = len - (k - 1); r <= n; r++) f[!t][r] = INT64_MAX;
multiset<int64_t> S;
S.insert(f[t][len] + a[len]);
for (int l = 1, r = len - (k - 1); r <= n; l++, r++) {
if (r + k <= n) S.insert(f[t][r + k] + a[r + k]);
f[!t][r] = *S.begin() + a[l];
if (l >= k) f[!t][r] = min(f[!t][r], f[t][r] + 2 * a[l]);
if (r >= len + 1) S.erase(S.find(f[t][r] + a[r]));
}
}
cout << ans << endl;
return;
}
int main() {
ios::sync_with_stdio(false), cin.tie(nullptr);
int _ = 1;
while (_--) solve();
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3636kb
input:
5 7 ..g.... ....... h.i.j.k abcde.f ..lmn.o hbgdj.k a.ime.f ..c.n.o ..l.... .......
output:
0
result:
wrong answer 1st lines differ - expected: 'yes', found: '0'