QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#732914 | #9574. Strips | ucup-team5008# | RE | 0ms | 3848kb | C++23 | 1.5kb | 2024-11-10 16:24:56 | 2024-11-10 16:24:56 |
Judging History
answer
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <vector>
const int N = 100005;
int n, m, k, w, a[N], b[N], lr[N], rr[N];
std::vector<int> ans;
bool solve(int l, int r, int lb, int rb) {
int wall_l = lb, wall_r = lb;
for (int i = l; i < r; ++i) {
if (i != l && wall_r >= a[i]) {
wall_l = a[i];
lr[i] = rr[i] = -1;
} else {
lr[i] = std::max(a[i] - k + 1, wall_l + 1);
if (lr[i] > a[i]) return false;
rr[i] = std::min(a[i], rb - k);
if (lr[i] > rr[i]) return false;
wall_l = lr[i] + k - 1;
wall_r = rr[i] + k - 1;
}
//printf("for %d : %d %d\n", i, lr[i] + 1, rr[i] + 1);
}
int rwall = rb;
for (int i = r - 1; i >= l; --i) if (lr[i] != -1) {
int p = std::min(rwall - k, rr[i]);
//printf("rwall is %d\n", rwall + 1);
//printf("put %d on %d\n", i, p + 1);
assert(p >= lr[i]);
rwall = p;
ans.push_back(p);
}
return 1;
}
void presolve() {
scanf("%d%d%d%d", &n, &m, &k, &w);
for (int i = 0; i < n; ++i) {
scanf("%d", a + i);
--a[i];
}
for (int i = 0; i < m; ++i) {
scanf("%d", b + i);
--b[i];
}
b[m++] = -1;
b[m++] = w;
std::sort(a, a + n);
std::sort(b, b + m);
ans.clear();
for (int i = 0, j = 0; i < m; ++i) {
int jj = j;
while (j < n && a[j] < b[i + 1]) ++j;
if (jj < j && !solve(jj, j, b[i], b[i + 1])) {
printf("-1\n");
return;
}
}
printf("%d\n", (int)ans.size());
for (int i = 0; i < (int)ans.size(); ++i) printf("%d ", ans[i] + 1);
printf("\n");
}
int main() {
int tt;
scanf("%d", &tt);
while (tt--) {
presolve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3848kb
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 10 7 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...