QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#425275#8574. Swirly Sortucup-team3215WA 7ms3632kbC++231.5kb2024-05-30 07:11:192024-05-30 07:11:19

Judging History

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

  • [2024-05-30 07:11:19]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:3632kb
  • [2024-05-30 07:11:19]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using pl = pair<ll, ll>;
constexpr ll INF = 1e16 + 1;

ll solver(const vector<ll> &a) {
    ll ans = 0;
    priority_queue<ll> Q;
    Q.push(a[0]);
    for (ll i = 1; i < a.size(); ++i) {
        ll t = a[i];
        Q.push(t);
        if (Q.top() > t) {
            ans += Q.top() - t;
            Q.pop();
            Q.push(t);
        }
    }
    return ans;
}

void solve() {
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for (auto &i: a)cin >> i;
    if (k == 1) {
        cout << solver(a) << "\n";
        return;
    }
    if (k == n) {
        ll res = INF;
        deque<ll> d(a.begin(), a.end());
        for (int i = 0; i < n; ++i) {
            d.push_back(d.front());
            d.pop_front();
            res = min(res, solver(vector<ll>(d.begin(), d.end())));
        }
        cout << res << "\n";
        return;
    }
    if (k >= 3 && (k - 3) % 2 == 0) {
        vector<pl> b;
        for (ll i = 0; i < n; ++i) {
            b.push_back({a[i], i});
        }
        sort(b.begin(), b.end());
        ll z = 0;
        for (ll i = 0; i < n; ++i) {
            z ^= b[i].second != i;
        }
        ll res = (!z ? INF : 0);
        for (ll i = 1; i < n; ++i)res = min(res, b[i].first - b[i - 1].first);
        cout << res << "\n";
    } else {
        cout << "0\n";
    }

}

int main() {
    cin.tie(0)->sync_with_stdio(false);
    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: 3592kb

input:

4
4 1
6 4 3 7
4 2
6 4 3 7
4 3
6 4 3 7
4 4
6 4 3 7

output:

3
0
1
2

result:

ok 4 number(s): "3 0 1 2"

Test #2:

score: -100
Wrong Answer
time: 7ms
memory: 3632kb

input:

10000
4 3
524728 254456 277709 19127
15 11
360089 525234 862619 897281 336644 910706 75922 708901 754517 734744 94169 326125 746826 846063 159956
4 2
140105 792522 40264 514789
12 2
270333 888927 500833 9065 936673 982631 332435 751429 607700 840339 804685 416612
8 7
119416 689632 517277 673646 8262...

output:

23253
0
0
0
15986
278544
0
0
0
0
0
0
0
0
0
9260
0
0
51255
0
0
277173
480146
0
658
0
25495
0
1928
0
0
266148
0
767231
5853
0
0
121885
0
788638
0
0
0
779611
0
0
0
0
0
0
517074
0
0
0
210836
454586
662851
0
781542
0
0
864957
175421
0
0
0
0
0
0
0
541010
0
0
15407
0
0
3413333
0
321
30512
0
19677
30305
309...

result:

wrong answer 2nd numbers differ - expected: '7691', found: '0'