QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#848970 | #9574. Strips | laonongmin | WA | 0ms | 3548kb | C++23 | 1.7kb | 2025-01-09 11:02:05 | 2025-01-09 11:02:11 |
Judging History
answer
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
// 检查是否能覆盖所有红色单元格
bool check(vector<int>& red, vector<int>& black, int k, int w) {
int n = red.size();
int m = black.size();
int i = 0, j = 0;
int cnt = 0;
while (i < n) {
int left = red[i];
int right = left + k - 1;
// 检查是否覆盖黑色单元格
bool flag = true;
while (j < m && black[j]<right) {
if (black[j] >= left) {
flag = false;
break;
}
j++;
}
if (flag) {
cnt++;
i = upper_bound(red.begin(), red.end(), right)-red.begin();
} else {
return false;
}
}
return true;
}
int main() {
int T;
cin >> T;
while (T--) {
int n, m, k, w;
cin >> n >> m >> k >> w;
vector<int> red(n);
for (int i = 0; i < n; i++) {
cin >> red[i];
}
sort(red.begin(), red.end());
vector<int> black(m);
for (int i = 0; i < m; i++) {
cin >> black[i];
}
sort(black.begin(), black.end());
if (check(red, black, k, w)) {
int i = 0;
int cnt = 0;
int left = red[0];
cnt++;
for (int j = 1; j < n; j++) {
if (red[j]>left + k - 1) {
left = red[j];
cnt++;
}
}
cout << cnt << endl;
} else {
cout << -1 << endl;
}
}
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3548kb
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 -1 2 2
result:
wrong answer Integer parameter [name=l_i] equals to -1, violates the range [1, 14] (test case 1)