QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#806122 | #9574. Strips | zhangwansen | WA | 0ms | 3552kb | C++23 | 2.1kb | 2024-12-08 21:51:47 | 2024-12-08 21:51:47 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
void solve()
{
int n, m, k, w;
cin >> n >> m >> k >> w;
vector<int> a(n + 1);
vector<int> b(m + 2);
for (int i = 1; i <= n; i++)
cin >> a[i];
b[0] = 0;
b[m + 1] = w + 1;
for (int i = 1; i <= m; i++)
cin >> b[i];
sort(a.begin(), a.end());
int idx = 1;
sort(b.begin(), b.end());
vector<int> res;
//0 7 8
for (int i = 1; i <= m + 1; i++)
{
int l = b[i - 1] + 1, r = b[i];//[l,r)可以放
// cout << l << ' '<< r << endl;
if(l >= r)
{
continue;
}
vector<int> c;//存放该区间的红格子
while (idx <= n && l <= a[idx] && a[idx] < r)
{
c.push_back(a[idx++]);
}
vector<int> t;
int rr = l - 1;
for (auto &lr : c)
{
if (lr > rr)
{
t.push_back(lr);
rr = lr + k - 1;
}
}
int idx = t.size() - 1;
while (idx >= 0 && t[idx] + k - 1 >= r)
{
t[idx] = r - k + 1;
r = t[idx] - 1;
idx--;
}
if (l > r)
{
puts("-1");
return;
}
//存放
// for(int j = t.size() - 1;j >= 0; j --)
// {
// int start = t[j];
// int end = t[j] + k -1;
// if(end >= r)
// {
// int new_start = r - k;
// if(new_start < l)
// {
// puts("-1");
// return;
// }
// t[j] = new_start;
// r = t[j];
// }
// else
// {
// break;
// }
// }
res.insert(res.end(), t.begin(), t.end());
}
cout << res.size() << endl;
for (auto &item : res)
{
cout << item << ' ';
}
cout << endl;
return;
}
signed main()
{
int t = 1;
cin >> t;
while (t--)
solve();
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3552kb
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 11 14 -1 2 1 5 -1
result:
wrong answer There is at least one stripe covering black cell 13 (test case 1)