QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#737824#9574. Stripsdreamjoker#WA 0ms3624kbC++231.8kb2024-11-12 16:56:162024-11-12 16:56:17

Judging History

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

  • [2024-11-12 16:56:17]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3624kb
  • [2024-11-12 16:56:16]
  • 提交

answer

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

void sol() {
    int n,m,k,w; cin>>n>>m>>k>>w;
    vector<int> a(n);
    vector<int> b(m);
    for(int i=0;i<n;i++) 
        cin>>a[i];
    for(int i=0;i<m;i++) 
        cin>>b[i];

    ranges::sort(a);
    ranges::sort(b);

    b.push_back(w+1);
    vector<int> ans;

    vector<int> tmp;
    auto solve=[&](int l,int r) {
        int n=tmp.size();
        if(!n) return true;

        vector<int> pos;
        for(int i=0,j=0;i<n;i=j) {
            pos.push_back(tmp[i]);
            while(j<n&&tmp[j]<tmp[i]+k) j++;
        }

        // cout<<"range: "<<l<<" "<<r<<endl;
        // for(int i:pos) 
        //     cout<<i<<' ';
        // cout<<endl;
        auto bias=[&](auto &&self,int x,int dis) {
            pos[x]-=dis;
            if(!x) return pos[x]>l;
            if(pos[x]<pos[x-1]+k) return self(self,x-1,pos[x-1]+k-pos[x]);
            return true;
        }; 
        if(pos.back()+k>r) {
            if(!bias(bias,n-1,pos.back()+k-r)) {
                // for(int i:pos) 
                //     cout<<i<<' ';
                // cout<<endl;
                return false;
            }
        }

        for(int x:pos) ans.push_back(x);
        return true;
    };

    for(int L=0,i=0;int R:b) {
        while(i<n&&a[i]<R) {
            tmp.push_back(a[i++]);
        }
        if(!solve(L,R)) {
            // cout<<"range: "<<L<<' '<<R<<endl;
            // for(int x:tmp) cout<<x<<' ';
            // cout<<endl;
            return cout<<-1<<'\n',void();
        }
        L=R;
        tmp.clear();
    }

    cout<<ans.size()<<'\n';
    for(int x:ans) 
        cout<<x<<' ';
    cout<<'\n';
}

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);

    int T; cin>>T;
    while(T--)
        sol();

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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:

-1
-1
2
1 5 
-1

result:

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