QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#771547 | #9574. Strips | q_zhs | WA | 0ms | 3804kb | C++17 | 2.3kb | 2024-11-22 14:03:57 | 2024-11-22 14:04:00 |
Judging History
answer
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
void solve() {
int T;
cin >> T;
for (int t = 0; t < T; ++t) {
int n, m, k, w;
cin >> n >> m >> k >> w;
vector<int> a(n);
for (int i = 0; i < n; ++i) cin >> a[i];
vector<int> b(m);
for (int i = 0; i < m; ++i) cin >> b[i];
sort(a.begin(), a.end());
sort(b.begin(), b.end());
vector<pair<int, int>> allowed_strips;
int prev = 0;
for (int i = 0; i < m; ++i) {
int s = prev + 1;
int e = b[i] - 1;
if (s > e) {
prev = b[i];
continue;
}
int l_start = s;
int l_end = e - k + 1;
if (l_end < l_start) {
prev = b[i];
continue;
}
for (int l = l_start; l <= l_end; ++l) {
allowed_strips.emplace_back(l, l + k - 1);
}
prev = b[i];
}
int s = prev + 1;
int e = w;
if (s > e) {
prev = w;
continue;
}
int l_start = s;
int l_end = e - k + 1;
if (l_end >= l_start) {
for (int l = l_start; l <= l_end; ++l) {
allowed_strips.emplace_back(l, l + k - 1);
}
}
sort(allowed_strips.begin(), allowed_strips.end(), [](const pair<int, int>& a, const pair<int, int>& b) {
return a.second < b.second;
});
vector<int> selected_strips;
int j = 0;
for (auto& strip : allowed_strips) {
if (j >= n) break;
if (strip.first <= a[j] && a[j] <= strip.second) {
selected_strips.push_back(strip.first);
while (j < n && a[j] <= strip.second) {
j++;
}
}
}
if (j == n) {
cout << selected_strips.size() << endl;
for (int l : selected_strips) {
cout << l << " ";
}
cout << endl;
} else {
cout << -1 << endl;
}
}
}
int main() {
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3804kb
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:
5 1 6 7 9 14 2 1 4 -1
result:
wrong answer There are more than one stripe covering cell 7 (test case 1)