QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#752040 | #9574. Strips | Hashbin | WA | 0ms | 3624kb | C++23 | 2.8kb | 2024-11-15 21:44:54 | 2024-11-15 21:44:56 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve()
{
int n, m, k, w;
cin >> n >> m >> k >> w;
vector<int> a(n + 10), b(m + 10);
for (int i = 1; i <= n; i++)
{
cin >> a[i];
}
for (int i = 1; i <= m; i++)
cin >> b[i];
b[++m] = w + 1;
sort(a.begin() + 1, a.begin() + n + 1);
sort(b.begin() + 1, b.begin() + m + 1);
int flag = 1;
vector<int> e;
auto check = [&](int l, int r) -> int
{
vector<int> q;
q.push_back(l - k + 1);
int cnt = 0;
int k1 = lower_bound(a.begin() + 1, a.begin() + n + 1, l) - a.begin();
int kk = lower_bound(a.begin() + 1, a.begin() + n + 1, r) - a.begin();
if (k1 == n + 1)
return 0;
int sum = 0;
for (int i = k1; i < kk; i++)
{
if (l >= a[i])
continue;
if (a[i] + k - 1 < r)
sum += a[i] - l - 1, l = a[i] + k - 1, cnt++, q.push_back(a[i]);
if (a[i] + k - 1 >= r)
{
int w = a[i] + k - 1 - r + 1;
if (sum >= w)
{
sum -= w, l = r - 1, cnt++;
int len = q.size() - 1;
int pos;
for (int j = len; j >= 1; j--)
{
if (q[j] - (q[j - 1] + k - 1) - 1 >= w)
{
q[j] -= w;
pos = j;
break;
}
else
{
w -= q[j] - (q[j - 1] + k - 1) - 1;
q[j] = q[j - 1] + k;
}
}
for (int j = pos + 1; j <= len; j++)
q[j] = q[j - 1] + k;
q.push_back(r - k);
}
else
{
flag = 0;
return 0;
}
}
}
if (!q.empty())
{
for(int i=1;i<q.size();i++) e.push_back(q[i]);
}
return cnt;
};
int ans = 0;
b[0] = 0;
for (int i = 1; i <= m; i++)
{
ans += check(b[i - 1], b[i]);
if (flag == 0)
{
cout << "-1" << '\n';
return;
}
}
if (w != b[m])
ans += check(b[m], w + 1);
if (flag == 0)
{
cout << "-1" << '\n';
return;
}
cout << ans << '\n';
for (auto x : e)
cout << x << ' ';
cout << '\n';
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int t = 1;
cin >> t;
while (t--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3624kb
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 6 10 14 -1 2 1 5 -1
result:
wrong answer There is no stripe covering red cell 9 (test case 1)