QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#746364 | #9574. Strips | surenjamts# | WA | 1ms | 3568kb | C++17 | 2.2kb | 2024-11-14 14:23:50 | 2024-11-14 14:23:50 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mk make_pair
#define S second
#define F first
vector<int> ans;
int k;
int comp(vector<int> red, int lt, int rt) {
if (rt == 0) return 0;
int n = red.size();
vector<int> dp(n + 1);
dp[n] = rt;
for (int i = n - 1; i >= 0; i--) {
int l = red[i] - k + 1;
int r = red[i] + 1;
if (red[i] >= dp[i + 1]) {
dp[i] = dp[i + 1];
continue;
}
// Binary search to find the best mid value
while (l + 1 < r) {
int mid = (l + r) / 2;
int next = lower_bound(red.begin() + i, red.end(), mid + k) - red.begin();
if (next >= n || mid + k > dp[next]) r = mid; // Adjust condition for edge case
else l = mid;
}
if (l <= lt) return -1;
dp[i] = l;
}
int cur = dp[0];
ans.push_back(cur);
for (int i = 1; i < n; i++) {
if (cur + k >= red[i]) continue;
cur = dp[i];
ans.push_back(cur);
}
return 0; // Added return statement to indicate success
}
void solve() {
ans.clear();
int n, m, w;
cin >> n >> m >> k >> w;
vector<int> a(n), b(m);
vector<pair<int, bool>> v;
v.emplace_back(0, 0);
for (int i = 0; i < n; i++) {
cin >> a[i];
v.emplace_back(a[i], 1);
}
for (int j = 0; j < m; j++) {
cin >> b[j];
v.emplace_back(b[j], 0);
}
v.emplace_back(w + 1, 0);
sort(v.begin(), v.end());
vector<int> red;
int blackprev = 0;
for (auto &[i, isred] : v) {
if (!isred) {
if (comp(red, blackprev, i) == -1) {
cout << "-1\n";
return;
}
blackprev = i;
red.clear();
} else {
red.push_back(i);
}
}
cout << ans.size() << '\n';
for (auto i : ans) {
cout << i << " ";
}
cout << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin >> t;
while (t--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3568kb
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)