QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#732595 | #9574. Strips | ucup-team059 | RE | 0ms | 3860kb | C++20 | 3.2kb | 2024-11-10 15:16:42 | 2024-11-10 15:16:43 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
void solve() {
int n, m, k, w;
std::cin >> n >> m >> k >> w;
std::vector<int> a(n), b(n);
std::vector<std::pair<int, int>> p;
for (int i = 0; i < n; i++){
std::cin >> a[i];
p.push_back({a[i], 0});
}
for (int i = 0; i < m; i++){
std::cin >> b[i];
p.push_back({b[i], 1});
}
p.push_back({0, 1});
p.push_back({w + 1, 1});
std::sort(p.begin(), p.end());
int siz = p.size();
int L = 0, R = 0, Li = 0, Ri = 0;
std::vector<int> ans;
while(Li < siz){
while (p[Li].second == 1){
Li++;
}
Ri = Li;
std::vector<int> r;
while (p[Ri].second == 0){
r.push_back(p[Ri].first);
Ri++;
}
L = p[Li - 1].first + 1;
R = p[Ri].first - 1;
// std::cout << L << " " << R << '\n';
// for (auto z : r){
// std::cout << z << " ";
// }
// std::cout << '\n';
if (!r.empty()) {
std::stack<int> block;
block.push(r[0] - L);
int st = 0;
std::vector<int> ret;
ret.push_back(r[0]);
for (int i = 1; i < r.size(); i++){
while (r[i] - r[st] < k){
i++;
}
int ed = r[st] + k - 1;
block.push(r[i] - ed - 1);
st = i;
ret.push_back(r[i]);
}
int ed = ret.back() + k - 1;
// for (auto z : ret){
// std::cout << z << ' ';
// }
// std::cout << '\n';
int x = ed - R;
if (x > 0){
int j = ret.size() - 1;
int Fn = ret.back();
assert(ret.size() == block.size());
while (!block.empty() && x){
int y = block.top();
block.pop();
int d = std::min(y, x);
x -= d;
Fn -= d;
j--;
if (d == y){
if (j == -1) Fn = L;
else
Fn = ret[j];
}
}
if (x){
std::cout << -1 << '\n';
return;
}
int lst = Fn;
for (int i : ret){
if (i < Fn){
ans.push_back(i);
}else{
ans.push_back(lst);
lst += k;
}
}
}else{
for (int i : ret){
ans.push_back(i);
}
}
}
Li = Ri + 1;
}
std::cout << ans.size() << '\n';
for (int i = 0; i < ans.size(); i++){
std::cout << ans[i] << " \n"[i == (int)ans.size() - 1];
}
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t;
std::cin >> t;
while (t--){
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3860kb
input:
4 5 2 3 16 7 11 2 9 14 13 5 3 2 4 11 6 10 2 1 11 2 1 2 6 1 5 3 2 1 2 6 1 5 2
output:
4 2 7 10 14 -1 2 1 5 -1
result:
ok ok 4 cases (4 test cases)
Test #2:
score: -100
Runtime Error
input:
11000 3 8 2 53 32 3 33 35 19 38 20 1 30 10 6 7 10 1 42 3 14 4 36 28 40 22 17 20 12 41 27 7 1 19 13 9 6 6 13 78 55 76 53 32 54 58 62 45 21 4 7 61 8 7 3 68 9 26 54 31 22 3 38 65 34 16 58 47 52 29 53 5 8 4 33 33 5 30 6 15 27 12 9 28 19 2 13 10 6 1 2 48 8 12 48 1 41 31 40 7 6 7 61 20 19 30 52 49 17 40 3...