QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#765838 | #9574. Strips | zxcdxw | RE | 0ms | 3564kb | C++14 | 1.8kb | 2024-11-20 15:23:37 | 2024-11-20 15:23:37 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define ll long long
#define lowbit(x) (x)&(-x)
//#define int long long
//#define double long double
const int N = 2e5 + 5;
const ll base = 131;
const ll mod = 998244353;
void solve() {
int n, m, k, w;
cin >> n >> m >> k >> w;
vector<int>a(n + 1), b(m + 1);
for (int i = 1; i <= n; ++i) cin >> a[i];
for (int i = 1; i <= m; ++i) cin >> b[i];
vector<pair<int, int>>x(n + m + 1);
vector<int>as;
for (int i = 1; i <= n; ++i) x[i] = { a[i],1 };
for (int i = n+1; i <=n+m; ++i) x[i] = { b[i-n],0 };
sort(x.begin() + 1, x.end());
x[0] = { 0,0 };
x.push_back({ w + 1,0 });
int l = 0, r = 1, ans = 0, now = -1;
while ( r <= n +m+ 1) {
while (r <= n + 1+m && x[r].second != 0) {
if (x[r].first > now) now = x[r].first + k - 1, ans++, as.push_back(x[r].first);
r++;
}
if (now >= x[r].first) {
int rr = r - 1, noww = x[r].first - k, xx = ans-1;
as[xx] = noww;
xx--;
bool ok = false;
while (rr > l) {
rr--;
if (rr == l) break;
if (noww <= x[rr].first) continue;
if (noww > x[rr].first + k - 1) continue;
else noww = noww - k, as[xx] = noww, xx--;
}
if (noww > x[l].first) ok = true;
if (!ok) {
cout << -1 << '\n';
return;
}
}
l = r;
r++;
now = -1;
}
cout << ans << '\n';
if (!ans) return;
for (auto& it : as) cout << it << " ";
cout << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t = 1;
cin >> t;
while (t--) solve();
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3564kb
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
Runtime Error
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...