QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#764010 | #8981. Kangaroo Puzzle | zxcdxw | WA | 1ms | 3848kb | C++14 | 1.9kb | 2024-11-19 23:19:50 | 2024-11-19 23:19:51 |
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) {
ok = true;
break;
}
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();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3848kb
input:
4 4 1111 1001 1001 1110
output:
-1 1 0 1 0 1 0
result:
wrong answer Line [name=ans] equals to "-1", doesn't correspond to pattern "[UDLR]{1,50000}"