QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#732642 | #9574. Strips | ucup-team059 | WA | 29ms | 3776kb | C++20 | 3.3kb | 2024-11-10 15:24:07 | 2024-11-10 15:24:08 |
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(m);
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 (Li < siz && p[Li].second == 1){
Li++;
}
Ri = Li;
std::vector<int> r;
while (Ri < siz && p[Ri].second == 0){
r.push_back(p[Ri].first);
Ri++;
}
if (Li >= siz) break;
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 (i < r.size() && 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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3776kb
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
Wrong Answer
time: 29ms
memory: 3648kb
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...
output:
3 3 32 0 7 3 4 14 22 28 36 40 4 32 53 0 66 8 3 9 22 26 31 38 54 65 5 5 0 15 30 0 6 1 8 12 31 41 47 6 17 0 30 39 49 0 3 52 67 0 2 27 0 2 22 0 1 62 6 24 33 43 48 60 0 3 4 31 0 3 11 20 31 3 3 16 33 3 25 30 42 4 3 17 0 60 4 1 11 21 33 2 54 66 4 50 59 65 0 5 50 62 0 78 30 2 85 0 4 2 11 16 23 6 3 7 17 36 ...
result:
wrong answer Integer parameter [name=l_i] equals to 0, violates the range [1, 52] (test case 1)