QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#781007#8679. Tilting Tilesucup-team5217WA 0ms3636kbC++231.1kb2024-11-25 14:23:232024-11-25 14:23:23

Judging History

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

  • [2024-11-25 14:23:23]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3636kb
  • [2024-11-25 14:23:23]
  • 提交

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;
}

Details

Tip: Click on the bar to expand more detailed information

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'