QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#729303 | #9574. Strips | ytck# | WA | 24ms | 5628kb | C++17 | 4.3kb | 2024-11-09 16:51:39 | 2024-11-09 16:51:40 |
Judging History
answer
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define endl '\n'
#define PII pair<int, int>
#define int long long
// #define int __int128
using namespace std;
inline int read();
inline void write(int x);
const int N = 2e5 + 10, mod = 998244353, inf = 2e18, base = 131;
int a[N], b[N];
void solves()
{
int n, m, k, w;
cin >> n >> m >> k >> w;
for (int i = 1; i <= n; i++)
cin >> a[i];
b[0] = 0, b[m + 1] = w + 1;
for (int i = 1; i <= m; i++)
cin >> b[i];
sort(a + 1, a + 1 + n), sort(b + 1, b + 1 + m);
int pos = 1;
int ans = 0;
vector<PII> res;
for (int i = 1; i <= m + 1; i++)
{
int l = b[i - 1] + 1, r = b[i] - 1;
if (l > r)
continue;
vector<int> t;
while (pos <= n && a[pos] <= r)
{
t.push_back(a[pos]);
pos++;
}
// cout << "***" << endl;
// cout << "l r :" << l << ' ' << r << endl;
// for (auto item : t)
// cout << item << ' ';
// cout << endl;
bool label = false;
vector<PII> sc;
for (int j = 0; j < t.size(); j++)
{
if (!sc.size())
{
int L = t[j], R = t[j] + k - 1;
if (R <= r)
{
sc.push_back({L, R});
}
else
{
label = true;
break;
}
}
else
{
int bl = sc.back().first, br = sc.back().second;
if (t[j] >= bl && t[j] <= br)
continue;
int L = t[j], R = t[j] + k - 1;
if (R <= r)
{
sc.push_back({L, R});
}
else
{
label = true;
break;
}
}
}
// cout<<"SC: "<<endl;
// cout<<label<<endl;
// for(auto item:sc) cout<<item.first<<' '<<item.second<<endl;
if (label)
{
if (sc.size() == 0)
{
int R = r;
int L = r - k + 1;
if (L < l)
{
cout << -1 << endl;
return;
}
}
else
{
vector<PII> sb;
int R = r;
int L = r - k + 1;
while (1)
{
int ll = sc.back().first, rr = sc.back().second;
if (rr <= R && rr >= L)
{
sc.pop_back();
sb.push_back({L, R});
R = L - 1, L = R - k + 1;
}
else
{
sb.push_back({L, R});
ans += sc.size() + sb.size();
for (auto item : sc)
res.push_back(item);
for (auto item : sb)
res.push_back(item);
break;
}
if (sc.size() == 0)
{
if (L < l)
{
cout << -1 << endl;
return;
}
else
{
sb.push_back({L, R});
ans += sb.size();
for (auto item : sb)
res.push_back(item);
break;
}
}
}
}
}
else
{
for (auto item : sc)
res.push_back(item);
ans += sc.size();
}
}
// cout<<"***********"<<endl;
cout << ans << endl;
for (auto item : res)
cout << item.first << ' ';
cout << endl;
}
signed main()
{
IOS;
int t = 1;
cin >> t;
while (t--)
solves();
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 5628kb
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: 24ms
memory: 3644kb
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 1 32 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 0 4 33 43 48 60 2 4 31 2 11 20 2 3 16 3 25 30 42 3 3 17 60 3 21 11 1 2 54 66 3 50 59 65 3 50 62 78 0 3 2 16 23 4 7 17 36 49 0 0 0 3 9 32 29 3 25 27 44 3 7...
result:
wrong answer There is no stripe covering red cell 53 (test case 3)