QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#732934#9574. Stripsucup-team5008#WA 24ms3908kbC++231.5kb2024-11-10 16:33:072024-11-10 16:33:08

Judging History

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

  • [2024-11-10 16:33:08]
  • 评测
  • 测评结果:WA
  • 用时:24ms
  • 内存:3908kb
  • [2024-11-10 16:33:07]
  • 提交

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 = std::max(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;
}

詳細信息

Test #1:

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

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
Wrong Answer
time: 24ms
memory: 3908kb

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:

2
3 32 
7
4 3 14 22 40 36 28 
3
32 48 66 
8
9 3 26 22 31 38 54 65 
3
5 15 30 
6
31 12 8 1 47 41 
4
17 39 30 49 
2
67 52 
1
27 
1
22 
1
62 
5
24 43 33 60 48 
2
4 31 
3
20 11 31 
3
3 16 33 
3
30 25 42 
3
3 17 60 
4
21 11 1 33 
2
66 54 
3
50 59 65 
3
62 50 78 
1
81 
4
2 11 23 16 
5
3 7 36 17 49 
2
1 45...

result:

wrong answer Participant didn't find a solution but the jury found one. (test case 73)