QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#729574#9574. Stripsucup-team4801#WA 29ms3908kbC++142.1kb2024-11-09 17:24:072024-11-09 17:24:08

Judging History

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

  • [2024-11-09 17:24:08]
  • 评测
  • 测评结果:WA
  • 用时:29ms
  • 内存:3908kb
  • [2024-11-09 17:24:07]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

const int N = 1e5 + 5;

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 - 1;
    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, 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();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 29ms
memory: 3908kb

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
-1 2 5 9 18 19 32 34 37 
14
0 4 3 7 9 12 14 17 19 22 40 36 28 41 
7
-12 -8 -5 22 46 49 64 
10
7 1 24 20 30 36 45 50 54 63 
9
-3 3 6 7 9 14 16 24 30 
6
30 11 7 1 47 41 
8
-6 -3 -2 14 18 34 27 47 
10
-10 -9 17 18 65 42 85 86 88 89 
5
-9 0 27 32 36 
5
-28 -22 9 23 27 
7
-7 6 8 25 62 63 65 
8
-1 2 24 ...

result:

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