QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#728992#9574. Stripsucup-team4801#WA 31ms4080kbC++141.7kb2024-11-09 16:19:232024-11-09 16:19:23

Judging History

你现在查看的是最新测评结果

  • [2024-11-09 16:19:23]
  • 评测
  • 测评结果:WA
  • 用时:31ms
  • 内存:4080kb
  • [2024-11-09 16:19:23]
  • 提交

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){
    int t = l, lst = L;

    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(){
    // freopen("in", "r", stdin);

    int T;
    scanf("%d", &T);

    while(T --)solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 4080kb

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 
-1
2
1 4 
-1

result:

ok ok 4 cases (4 test cases)

Test #2:

score: -100
Wrong Answer
time: 31ms
memory: 3800kb

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:

9
2 2 31 31 31 31 32 36 39 
14
3 3 4 14 14 14 14 22 22 22 28 36 40 42 
7
20 20 20 22 46 64 64 
10
1 7 20 24 30 36 52 53 54 63 
9
2 3 12 12 13 14 27 28 30 
6
1 7 11 30 41 47 
8
11 11 11 14 25 27 34 47 
10
42 42 42 42 42 65 96 97 99 100 
5
18 18 27 42 46 
5
1 7 9 52 56 
7
62 62 62 62 62 71 73 
8
24 24...

result:

wrong answer Integer parameter [name=c] equals to 9, violates the range [-1, 3] (test case 1)