QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#729278 | #9574. Strips | ucup-team4801# | WA | 23ms | 3912kb | C++14 | 2.1kb | 2024-11-09 16:49:29 | 2024-11-09 16:49:31 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5;
int f[N];
int a[N], b[N];
int K;
vector<int> ans;
bool solve(int l, int r, int L, int R){
f[l - 1] = L;
for(int i = l; i <= r; i ++){
int u = upper_bound(a + l, a + i + 1, a[i] - K) - a;
f[i] = max(f[u - 1] + K - 1, a[i]);
}
if(f[r] > R)return 0;
int t = r;
while(1){
int u = upper_bound(a + l, a + t + 1, a[t] - K) - a;
int pos = f[t] - K + 1;
ans.push_back(pos);
t = u - 1;
if(t < l)break;
}
return 1;
// vector<int> res;
// while(1){
// int u = lower_bound(a + t + 1, a + r + 1, a[t] + K) - a;
// int pos = max(lst, a[u - 1] - K + 1);
// res.push_back(pos); lst = pos + K;
// if(lst > R + 1)break;
// t = u;
// if(t > r)break;
// }
// if(t > r){
// for(int u : res)ans.push_back(u);
// return 1;
// }
// res.clear();
// t = r;
// lst = R;
// while(1){
// int u = upper_bound(a + l, a + t + 1, a[t] - K) - a;
// int pos = min(lst - K + 1, a[u]);
// res.push_back(pos); lst = pos - 1;
// if(lst < L - 1)break;
// t = u - 1;
// if(t < l)break;
// }
// if(t < l){
// for(int u : res)ans.push_back(u);
// return 1;
//
// return 0;
}
void solve(){
ans.clear();
int n, m, w;
scanf("%d%d%d%d", &n, &m, &K, &w);
for(int i = 1; i <= n; i ++)scanf("%d", &a[i]);
for(int i = 1; i <= m; i ++)scanf("%d", &b[i]);
b[++ m] = 0; b[++ m] = w + 1;
sort(a + 1, a + n + 1);
sort(b + 1, b + m + 1);
int j = 1;
for(int i = 1; i < m; i ++){
int l = j;
while(j <= n && a[j] < b[i + 1])j ++;
if(!solve(l, j - 1, b[i] + 1, b[i + 1] - 1)){
puts("-1");
return ;
}
}
printf("%d\n", (int)ans.size());
for(int u : ans){
printf("%d ", u);
}
puts("");
}
int main(){
int T;
scanf("%d", &T);
while(T --)solve();
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3904kb
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 9 6 14 -1 2 1 4 -1
result:
ok ok 4 cases (4 test cases)
Test #2:
score: -100
Wrong Answer
time: 23ms
memory: 3912kb
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:
-1 -1 -1 -1 -1 6 30 11 7 1 47 41 -1 -1 -1 5 -27 -21 9 24 28 7 -6 7 9 26 62 64 66 8 0 3 24 42 33 60 47 66 3 3 31 59 -1 -1 5 1 30 25 32 42 6 2 5 17 30 44 59 -1 -1 -1 7 -8 5 29 60 43 78 81 2 -15 78 4 1 11 21 15 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 5 -2 40 35 89 84 9 16 20 26 32 34 38 43 47 50...
result:
wrong answer Participant didn't find a solution but the jury found one. (test case 1)