QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#837052 | #9574. Strips | laonongmin | WA | 0ms | 3516kb | C++20 | 1.7kb | 2024-12-29 14:28:57 | 2024-12-29 14:28:57 |
Judging History
answer
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
// 检查条带是否合法(不覆盖黑色单元格)
bool is_valid(const vector<int>& red_cells, const vector<int>& black_cells, int left, int k) {
for (int b : black_cells) {
for (int i = left; i < left + k; i++) {
if (i == b) {
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_cells(n);
for (int i = 0; i < n; i++) {
cin >> red_cells[i];
}
vector<int> black_cells(m);
for (int i = 0; i < m; i++) {
cin >> black_cells[i];
}
// 对红色单元格排序
sort(red_cells.begin(), red_cells.end());
int count = 0;
int i = 0;
vector<int> ans;
while (i < n) {
int left = red_cells[i];
// 寻找合适的条带位置
while (!is_valid(red_cells, black_cells, left, k)) {
left++;
if (left + k - 1>w) {
// 无法找到合适的条带位置
cout << -1 << endl;
goto end;
}
}
count++;
ans.push_back(left);
i += k;
}
cout << count << endl;
for (int j = 0; j < count; j++) {
cout << ans[j];
if (j!= count - 1) {
cout << " ";
}
}
cout << endl;
end:;
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3516kb
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:
2 2 14 1 2 1 1 1 3
result:
wrong answer There is no stripe covering red cell 7 (test case 1)