QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#713202 | #9574. Strips | ucup-team1196# | WA | 36ms | 3876kb | C++23 | 2.3kb | 2024-11-05 18:35:58 | 2024-11-05 18:35:59 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve() {
int n, m, k, w;
std::cin >> n >> m >> k >> w;
std::vector<int> a(n + 1), b(m + 3);
b[1] = 0;
for (int i = 1; i <= n; i++) {
std::cin >> a[i];
}
std::map<int, int> isb;
for (int i = 2; i <= m + 1; i++) {
std::cin >> b[i];
isb[b[i]] = 1;
}
b[m + 2] = w + 1;
for (int i = 1; i <= n; i++) {
if (isb[a[i]]) {
std::cout << "-1\n";
return;
}
}
std::sort(a.begin() + 1, a.end());
std::sort(b.begin() + 1, b.end());
std::vector<int> res;
int j = 1;
int ans = 0;
for (int i = 2; i <= m + 2; i++) {
int L = b[i - 1] + 1;
int R = b[i] - 1;
// std::cerr << L << " " << R << "\n";
std::vector<int> vec;
while(j <= n && a[j] < R) {
vec.push_back(a[j]);
j++;
}
// std::cerr << "!!!" << L << " " << R << std::endl;
// for (auto x : vec) {
// std::cerr << x << " ";
// }
// std::cerr << std::endl;
if (vec.size() == 0) {
continue;
}
std::vector<int> q;
for (auto x : vec) {
if (q.size() == 0 || q.back() + k - 1 < x) {
q.push_back(x);
}
}
for (int i = q.size() - 1; i >= 0; i--) {
if (i == q.size() - 1) {
if (q[i] + k - 1 > R) {
q[i] = R - k + 1;
}
} else {
if (q[i] + k - 1 > q[i + 1]) {
q[i] = q[i + 1] - k + 1;
}
}
}
for (auto x : q) {
res.push_back(x);
}
if (q[0] < L) {
ans += 1000000000;
} else {
ans += q.size();
}
}
std::cout << (ans < 1E9 ? ans : -1) << "\n";
if (ans < 1E9) {
for (auto x : res) {
std::cout << x << " ";
}
std::cout << "\n";
}
}
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
// freopen("K.in", "r", stdin);
int t = 1;
std::cin >> t;
while (t --) {
solve();
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3608kb
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 7 10 14 -1 2 1 5 -1
result:
ok ok 4 cases (4 test cases)
Test #2:
score: -100
Wrong Answer
time: 36ms
memory: 3876kb
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 -1 3 32 48 66 8 3 9 22 26 31 38 54 65 3 5 15 30 5 1 8 12 31 41 4 17 30 39 49 2 52 67 1 27 1 22 -1 -1 2 4 31 3 11 20 31 -1 -1 3 3 17 60 4 2 12 21 33 2 54 66 3 50 59 65 3 50 62 78 1 81 -1 -1 2 1 45 2 7 25 1 4 -1 3 25 27 44 3 7 8 36 -1 1 13 4 8 25 45 57 1 38 -1 4 35 43 8...
result:
wrong answer Participant didn't find a solution but the jury found one. (test case 2)