QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#759536 | #9574. Strips | zaqmju | WA | 0ms | 3516kb | C++23 | 2.0kb | 2024-11-18 09:52:11 | 2024-11-18 09:52:12 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const int N = 1e5 + 10;
int a[N], b[N];
vector<int> ans;
void solve() {
ans.clear();
int n, m, k, w;
cin >> n >> m >> k >> w;
// vector<int> a(n + 2), b(m + 2);
for(int i = 1; i <= n; i++) {
cin >> a[i];
}
for(int i = 1; i <= m; i++) {
cin >> b[i];
}
a[0] = 0; a[n + 1] = w + 2;
b[0] = 0; b[m + 1] = w + 1;
// sort(a.begin() + 1, a.end());
sort(a + 1, a + 1 + n);
sort(b + 1, b + 1 + m);
// cout << a[1] << endl;
// for(int i = 1; i <= n; i++)cout << a[i] << " \n"[i == n];
// sort(b.begin() + 1, b.end());
// vector<int> ans;
// auto g = upper_bound(r.begin() + 1, r.end(), 6) - (r.begin() + 1);
// cout << g << endl;
int l, r;
int cnt = 1;
bool flag = false;
for(int i = 0; i <= m; i++) {
l = cnt, r = cnt;
if(cnt == n + 1)break;
if(b[i + 1] < a[cnt])continue;//b[i]---b[i + 1]中间没有黑色的
while(a[r] >= b[i] && a[r] <= b[i + 1]) {
r++;
}
cnt = r;
r -= 1;
// cout << l << " " << r << endl;
vector<int> res;
for(int j = l; j <= r; j++) {//段内所有的红色
if(j == l) {
res.push_back(a[j]);
}
else {
if(a[j] <= res.back() + k - 1) continue;
else res.push_back(a[j]);
}
}
res.push_back(b[i + 1]);
for(int j = (int)res.size() - 1; j >= 0; j--) {
// cout << a[j] << endl;
if(res[j] + k - 1 >= res[j + 1]) {
// cout << a[j] << " " << a[j + 1] << endl;
int t = res[j + 1] - k;
res[j] = t;
}
}
if(res[0] <= b[i]) {
// cout << res[0];
// cout << -1 << endl;
// return;
flag = 1;
break;
}
else {
for(int i = 0; i < (int)res.size() - 1; i++) {
ans.push_back(res[i]);
}
}
}
if(flag) {
cout << -1 << endl;
}
else {
cout << ans.size() << endl;
for(int i: ans)cout << i << " ";
cout << endl;
}
}
#undef int
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t = 1;
cin >> t;
while(t--) {
solve();
}
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:
-1 -1 -1 -1
result:
wrong answer Participant didn't find a solution but the jury found one. (test case 1)