QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#805816#9574. Stripszhangwansen#WA 24ms3680kbC++233.7kb2024-12-08 18:45:432024-12-08 18:45:44

Judging History

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

  • [2024-12-08 18:45:44]
  • 评测
  • 测评结果:WA
  • 用时:24ms
  • 内存:3680kb
  • [2024-12-08 18:45:43]
  • 提交

answer

#include <bits/stdc++.h>

#define int long long

using namespace std;

constexpr int INF = 1e9;

void solve(){
    int n,m,k,w;
    cin>>n>>m>>k>>w;
    //1 red, 2 black
    vector<array<int,2>> vec;
    for(int i=0;i<n;i++){
        int pos;
        cin>>pos;
        vec.push_back({pos,1});
    }
    for(int i=0;i<m;i++){
        int pos;
        cin>>pos;
        vec.push_back({pos,2});
    }
    vec.push_back({0,2});
    vec.push_back({w + 1,2});
    sort(vec.begin(),vec.end());
    vector<int> black;
    for(int i=0;i<vec.size();i++){
        if(vec[i][1] == 2){
            black.push_back(i);
        }
    }
    int ans = 0;
    vector<int> temp1,temp2;
    auto check = [&](int num,int l,int r){
        temp1.clear();
        temp2.clear();
        int res1=0;
        int i = l;
        int L  = -1;
        int blkr = vec[r + 1][0];
        int blkl = vec[l - 1][0];
        while(i <= r){
            auto [pos,col] = vec[i];
            if(L==-1){
                L = pos;
                temp1.push_back(L);
                res1++;
            } else {
                if(pos - L + 1 > k){
                    if(pos + k - 1 >= blkr){
                        if(L+k-1>=blkr - k){
                            res1 = INF;
                            break;
                        }
                        L = blkr - k;
                        temp1.push_back(L);
                        res1++;
                    }else{
                        L = pos;
                        temp1.push_back(L);
                        res1++;
                    }
                }
            }
            i++;
        }
        i = r;
        int R  = -1;
        int res2=0;
        while(i >= l){
            auto [pos,col] = vec[i];
            if(R==-1){
                if(pos - k + 1 <= blkl){
                    R = blkl + k;
                }else{
                    R = pos;
                }
                temp2.push_back(R-k+1);
                res2++;
            } else {
                if(R - pos + 1 > k){
                    if(pos - k + 1 <= blkl){
                        if(blkl + k >= R - k + 1){
                            res2 = INF;
                            break;
                        }
                        R = blkl + k;
                        temp2.push_back(R-k+1);
                        res2++;
                    }else{
                        R = pos;
                        temp2.push_back(R-k+1);
                        res2++;
                    }
                }
            }
            i--;
        }
        if(res1<res2){
            temp2.clear();
        }else{
            temp1.clear();
        }
        return min(res1,res2) <= num;
    };
    vector<int> op;
    for(int i=0;i<black.size() - 1;i++){
        int len = (vec[black[i+1]][0]-vec[black[i]][0]) - 1;
        int l = 0,r = len / k;
        while(l<r){
            int m = (l+r)/2;
            if(check(m,black[i]+1,black[i+1]-1)){
                r=m;
            }else{
                l=m+1;
            }
        }
        if(check(l,black[i]+1,black[i+1]-1)){
            op.insert(op.end(),temp1.begin(),temp1.end());
            op.insert(op.end(),temp2.begin(),temp2.end());
            ans+=l;
        }else{
            cout<<-1<<endl;
            return;
        }
    }
    cout << ans << endl;
    assert(ans==op.size());
    for(auto item:op){
        cout<<item<<" ";
        assert(item>=1&&item<=w);
    }
    cout<<endl;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t;
    cin >> t;
    while (t--){
      solve();
    }
}

详细

Test #1:

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

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: 24ms
memory: 3680kb

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
2 32 
7
4 3 14 22 40 36 28 
3
22 46 64 
8
7 1 24 20 30 36 54 63 
3
3 14 30 
6
30 11 7 1 47 41 
4
14 34 27 47 
2
65 42 
1
27 
1
9 
1
62 
5
24 42 33 60 47 
2
3 31 
3
11 20 29 
3
2 15 33 
3
30 25 42 
3
2 17 59 
-1
2
65 53 
3
49 58 65 
3
60 43 78 
1
78 
4
1 11 21 15 
5
3 7 36 17 48 
2
1 44 
2
7 25 
1
...

result:

wrong answer Participant didn't find a solution but the jury found one. (test case 18)