QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#224903 | #7617. Spectacle | SolitaryDream# | WA | 0ms | 4120kb | C++17 | 1.3kb | 2023-10-23 17:18:09 | 2023-10-23 17:18:09 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
inline int Calc(pii a) {
return (a.second - a.first + 2) / 2;
}
int main() {
int n;
scanf("%d", &n);
vector<int> a(n);
for (int i = 0; i < n; ++i) {
scanf("%d", &a[i]);
}
sort(a.begin(), a.end());
vector<pii> dif;
for (int i = 0; i + 1 < n; ++i) {
dif.push_back({a[i + 1] - a[i], i});
}
sort(dif.begin(), dif.end());
map<int, int> mp;
int cur_pair = 0;
vector<int> ans(n / 2);
for (auto [d, x] : dif) {
int last_pair = cur_pair;
auto [it, _] = mp.insert({x, x});
++cur_pair;
if (it != mp.begin() && prev(it)->second == x - 1) {
cur_pair -= Calc(*it);
cur_pair -= Calc(*prev(it));
--it;
it->second = x;
cur_pair += Calc(*it);
mp.erase(next(it));
}
if (next(it) != mp.end() && next(it)->first == x + 1) {
++it;
cur_pair -= Calc(*it);
cur_pair -= Calc(*prev(it));
--it;
it->second = x;
cur_pair += Calc(*it);
mp.erase(next(it));
}
for (int i = last_pair; i < cur_pair; ++i) ans[i] = d;
}
for (auto x : ans) printf("%d ", x);
puts("");
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3888kb
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: 4120kb
input:
2 1 1000000000000000000
output:
1486618625
result:
wrong answer 1st lines differ - expected: '999999999999999999', found: '1486618625 '