QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#731435 | #9574. Strips | ucup-team1766# | TL | 0ms | 3596kb | C++23 | 1.4kb | 2024-11-10 04:02:17 | 2024-11-10 04:02:19 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
void run() {
int n, m, k, w; cin >> n >> m >> k >> w;
vector<pair<int,bool>> a;
while (n--) {
int x; cin >> x; x--;
a.emplace_back(x, 0);
}
while (m--) {
int x; cin >> x; x--;
a.emplace_back(x, 1);
}
ranges::sort(a);
a.emplace_back(w, 1);
int ans = 0, last = -1;
vector<array<int,3>> st {{0, 0, 0}}; // x, left, run
for (auto [x, t] : a) {
if (not t) {
if (x >= st.back()[0] + k*st.back()[2]) {
ans++;
st.push_back({x, x - max(last, st.back()[0] + k*st.back()[2]), 1});
while (st.size() > 2 and st[st.size()-2][0] + k*st[st.size()-2][2] == st.back()[0]) {
st[st.size()-2][2] += st.back()[2];
st.pop_back();
}
}
} else {
for (int total = st.back()[0] + k*st.back()[2] - x; total > 0;) {
int move = min(total, st.back()[1]);
st.back()[0] -= move;
st.back()[1] -= move;
total -= move;
while (st.size() > 2 and st[st.size()-2][0] + k*st[st.size()-2][2] == st.back()[0]) {
st[st.size()-2][2] += st.back()[2];
st.pop_back();
}
if (st.size() == 2 and not st.back()[1]) {
cout << "-1\n";
return;
}
}
last = x+1;
}
}
cout << ans << '\n';
for (unsigned i = 1; i < st.size(); i++) {
for (int j = 0; j < st[i][2]; j++) {
cout << st[i][0] + j*k + 1 << ' ';
}
}
cout << '\n';
}
int main() {
cin.tie(0)->sync_with_stdio(0);
int t; cin >> t; while (t--) run();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3596kb
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
Time Limit Exceeded
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...