QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#796301#9574. Stripshope_lbWA 0ms3556kbC++142.3kb2024-12-01 16:17:452024-12-01 16:17:47

Judging History

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

  • [2024-12-01 16:17:47]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3556kb
  • [2024-12-01 16:17:45]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using pll=pair<ll,ll>;
vector<ll>ve;
ll n,m,k,w;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    int tt;
    cin>>tt;
    while(tt--){
        vector<ll>ans;

        cin>>n>>m>>k>>w;
        vector<ll>red,blk;
        for(int i=0;i<n;i++){
            ll x;
            cin>>x;
            red.push_back(x);
        }
        for(int i=0;i<m;i++){
            ll x;
            cin>>x;
            blk.push_back(x);
        }
        blk.push_back(0),blk.push_back(w+1);
        sort(red.begin(),red.end()),sort(blk.begin(),blk.end());

        ll flag=0;
        ll posr=0,posb=0;
        while(posb<blk.size()-1){
            ll l=blk[posb],r=blk[posb+1];posb++;

            ve.clear();
            for(;posr<red.size();posr++){

                if(red[posr]>r)break;
                if(red[posr]>=l&&red[posr]<=r)ve.push_back(red[posr]);
            }

            if(ve.empty()){
                continue;
            }
            ll dis=ve[ve.size()-1]-ve[0]+1;
            ll tmp=dis/k;
            if(dis%k)tmp++;
            if(tmp*k>r-l-1){
                flag=1;
                break;
            }
            vector<ll>ans1;
            ll up=min((ll)ve.size(),(r-l-1)/k);
            ll sta=ve[0],ed=sta+k-1,pos=0;
            ll x=0;
            for(ll i=1;i<=up;i++){
                ans1.push_back(sta);
                while(pos<ve.size()&&ve[pos]<=ed){
                    pos++;
                }
                if(pos==ve.size()){
                    x=i;
                    break;
                }
                else {
                    sta=ve[pos],ed=sta+k-1;
                }
            }
            ll last=r-1;
            for(int i=ans1.size()-1;i>=0;i--){
                ll sta=ans1[i],ed=sta+k-1;
                if(ed>last){
                    ans1[i]-=ed-last;
                    last=ans[i]-1;
                }
                else break;
            }
            for(auto it:ans1){
                ans.push_back(it);
            }



        }
        if(flag){
            cout<<-1<<'\n';
            continue;
        }
        cout<<ans.size()<<'\n';
        for(auto it:ans)cout<<it<<' ';cout<<'\n';

    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3556kb

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 -3 10 14 
-1
2
1 5 
-1

result:

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