QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#222247#7617. Spectacleucup-team1191#WA 0ms3684kbC++201.5kb2023-10-21 16:25:092023-10-21 16:25:11

Judging History

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

  • [2023-10-21 16:25:11]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3684kb
  • [2023-10-21 16:25:09]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
#define TIME (clock() * 1.0 / CLOCKS_PER_SEC)

const int M = 2e5 + 239;

int par[M], sz[M], sm;

int find_set(int p) {
    if (par[p] == p) {
        return p;
    }
    return par[p] = find_set(par[p]);
}

void merge(int i, int j) {
    i = find_set(i);
    j = find_set(j);
    if (i == j) {
        return;
    }
    if (sz[i] > sz[j]) {
        swap(i, j);
    }
    sm -= sz[i] / 2;
    sm -= sz[j] / 2;
    par[i] = j;
    sz[j] += sz[i];
    sm += sz[j] / 2;
}

void solve() {
    int n;
    cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    vector<pair<ll, int>> v;
    for (int i = 0; i + 1 < n; i++) {
        v.emplace_back(a[i + 1] - a[i], i);
    }
    sort(v.begin(), v.end());
    for (int i = 0; i < n; i++) {
        par[i] = i;
        sz[i] = 1;
    }
    sm = 0;
    vector<ll> ans((n / 2), -1);
    for (auto [val, i] : v) {
        int last_sm = sm;
        merge(i, i + 1);
        for (int x = last_sm + 1; x <= sm; x++) {
            ans[x - 1] = val;
        }
    }
    for (int i : ans) {
        cout << i << " ";
    }
    cout << "\n";
}

int main() {
#ifdef ONPC
    freopen("input", "r", stdin);
#endif
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3648kb

input:

6
100 13 20 14 10 105

output:

1 5 6 

result:

ok single line: '1 5 6 '

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3684kb

input:

2
1 1000000000000000000

output:

-1486618625 

result:

wrong answer 1st lines differ - expected: '999999999999999999', found: '-1486618625 '