QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#734315 | #9574. Strips | orz_z | WA | 0ms | 3484kb | C++14 | 4.4kb | 2024-11-11 08:51:59 | 2024-11-11 08:52:05 |
Judging History
answer
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
//#pragma GCC optimize("Ofast,fast-math")
//#pragma GCC target("avx,avx2")
//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
//#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
//#define int long long
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef double db;
#define F(i, a, b) for(int i = a; i <= (b); ++i)
#define F2(i, a, b) for(int i = a; i < (b); ++i)
#define dF(i, a, b) for(int i = a; i >= (b); --i)
template<typename T> void debug(string s, T x) {
cerr << "[" << s << "] = [" << x << "]\n";
}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {
for (int i = 0, b = 0; i < (int)s.size(); i++) if (s[i] == '(' || s[i] == '{') b++;
else if (s[i] == ')' || s[i] == '}') b--;
else if (s[i] == ',' && b == 0) {
cerr << "[" << s.substr(0, i) << "] = [" << x << "] | ";
debug(s.substr(s.find_first_not_of(' ', i + 1)), args...);
break;
}
}
#ifdef ONLINE_JUDGE
#define Debug(...)
#else
#define Debug(...) debug(#__VA_ARGS__, __VA_ARGS__)
#endif
#define pb push_back
#define fi first
#define se second
#define Mry fprintf(stderr, "%.3lf MB\n", (&Med - &Mbe) / 1048576.0)
#define Try cerr << 1e3 * clock() / CLOCKS_PER_SEC << " ms\n";
typedef long long ll;
// namespace Fread {const int SIZE = 1 << 17; char buf[SIZE], *S, *T; inline char getchar() {if (S == T) {T = (S = buf) + fread(buf, 1, SIZE, stdin); if (S == T) return '\n';} return *S++;}}
// namespace Fwrite {const int SIZE = 1 << 17; char buf[SIZE], *S = buf, *T = buf + SIZE; inline void flush() {fwrite(buf, 1, S - buf, stdout), S = buf;} inline void putchar(char c) {*S++ = c;if (S == T) flush();} struct NTR {~NTR() {flush();}} ztr;}
// #ifdef ONLINE_JUDGE
// #define getchar Fread::getchar
// #define putchar Fwrite::putchar
// #endif
inline int ri() {
int x = 0;
bool t = 0;
char c = getchar();
while (c < '0' || c > '9') t |= c == '-', c = getchar();
while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
return t ? -x : x;
}
inline void wi(int x) {
if (x < 0) {
putchar('-'), x = -x;
}
if (x > 9) wi(x / 10);
putchar(x % 10 + 48);
}
inline void wi(int x, char s) {
wi(x), putchar(s);
}
bool Mbe;
// mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const int mod = 998244353;
const int inf = 0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3f;
const int _ = 2e5 + 5;
int n, m, k, w;
int a[_], b[_];
void solve(int Z, int T) {
n = ri(), m = ri(), k = ri(), w = ri();
F(i, 1, n) a[i] = ri();
F(i, 1, m) b[i] = ri();
sort(a + 1, a + n + 1);
sort(b + 1, b + m + 1);
// if(T == 11000) {
// if(Z == 48) {
// cout<< n << ' ' << m << ' ' << k << ' ' << w << '\n';
// F(i, 1, n) cout << a[i] << ' '; cout <<'\n';
// F(i, 1, m) cout << b[i] << ' '; cout <<'\n';
// }
// return;
// }
b[0] = 0, b[m + 1] = w + 1;
vector<pii> A;
F(i, 1, m + 1) if(b[i] > b[i - 1] + 1) {
A.pb(make_pair(b[i - 1] + 1, b[i] - 1));
}
for(pii v : A) if(v.se - v.fi + 1 < k) {
int l = lower_bound(a + 1, a + n + 1, v.fi) - a;
int r = upper_bound(a + 1, a + n + 1, v.se) - a - 1;
if(l <= r) {
puts("-1");
return;
}
}
// Debug("114");
vi ans;
for(pii v : A) {
Debug(v.fi, v.se);
int l = lower_bound(a + 1, a + n + 1, v.fi) - a;
int r = upper_bound(a + 1, a + n + 1, v.se) - a - 1;
if(l > r) continue;
int lst = v.fi - 1;
vi res;
F(j, l, r) {
int p = upper_bound(a + 1, a + n + 1, a[j] + k - 1) - a - 1;
Debug(p, a[p], max(lst + 1, a[p] - k + 1));
if(max(lst + 1, a[p] - k + 1) + k - 1 > v.se) {
int nw = v.se - k + 1;
dF(i, (int)res.size() - 1, 0) if(res[i] + k - 1 > nw){
res[i] = nw - k;
} else {
nw = res[i];
}
if(!res.empty() && res[0] < v.fi) {
puts("-1");
return;
}
res.pb(v.se - k + 1);
break;
}
Debug(l, r, j, p);
res.pb(max(lst + 1, a[p] - k + 1));
lst = max(lst + 1, a[p] - k + 1) + k - 1;
j = p;
}
for(int v : res) ans.pb(v);
}
cout << ans.size() << '\n';
for(int v : ans) cout << v << ' ';
cout <<'\n';
}
bool Med;
signed main() {
// Mry;
int T = ri();
F(z, 1,T) solve(z, T);
// Try;
return 0;
}
/*
24 196055605
ginganjingnanjingnanjing
1
6 1 3 67
8 26 28 30 41 66
27
*/
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3484kb
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 1 7 10 14 3 2 3 7 2 1 4 -1
result:
wrong answer There are more than one stripe covering cell 3 (test case 2)