QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#734291 | #9574. Strips | orz_z | WA | 23ms | 3816kb | C++14 | 4.4kb | 2024-11-11 08:36:27 | 2024-11-11 08:36:28 |
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() {
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);
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) {
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 fang = (v.se - v.fi + 1) / k;
int tot = (v.se - v.fi + 1) - fang * k; // 最少tot个不放
if(v.se - v.fi + 1 - (r - l + 1) < tot) {
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;
F(j, l, r) {
int p = upper_bound(a + 1, a + n + 1, a[j] + k - 1) - a - 1;
int L = max(lst + 1, a[j] - k + 1);
if(L + k - 1 > v.se) {
puts("-1");
return;
}
int l2 = L, r2 = min(a[j], v.se - k + 1), mid, R = L;
while(l2 <= r2) {
mid = (l2 + r2) >> 1;
int p = upper_bound(a + 1, a + n + 1, mid + k - 1) - a;
if((v.se - mid + 1) / k * k >= r - p + 1) {
R = mid;
l2 = mid+ 1;
} else r2 = mid - 1;
}
if(L > R) {
puts("-1");
return;
}
// 放在了 x
// v.se-x+1 - (r-p+1) >=(v.se - x + 1) % k
Debug(p, a[p], max(lst + 1, a[p] - k + 1));
if(max(lst + 1, a[p] - k + 1) + k - 1 > v.se) {
puts("-1");
return;
}
ans.pb(R);
lst = R + k - 1;
j = upper_bound(a + 1, a + n + 1, lst) - a - 1;
}
}
cout << ans.size() << '\n';
for(int v : ans) cout << v << ' ';
cout <<'\n';
}
bool Med;
signed main() {
// Mry;
int T = ri();
while(T--) solve();
// Try;
return 0;
}
/*
24 196055605
ginganjingnanjingnanjing
*/
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3620kb
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
Wrong Answer
time: 23ms
memory: 3816kb
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...
output:
2 3 32 7 3 4 14 22 28 36 40 3 32 48 66 8 3 9 22 26 31 38 54 65 3 5 15 30 6 1 8 12 31 41 47 4 17 30 39 49 2 52 67 1 27 1 22 1 62 5 24 33 43 48 60 2 4 31 3 11 20 31 3 3 16 33 3 25 30 42 3 3 17 60 -1 2 54 66 3 50 59 65 3 50 62 78 1 81 4 2 11 16 23 5 3 7 17 36 49 2 1 45 2 7 25 1...
result:
wrong answer Participant didn't find a solution but the jury found one. (test case 18)